diff --git a/builtin/providers/aws/resource_aws_elb.go b/builtin/providers/aws/resource_aws_elb.go index a613cbd80..ebc45c941 100644 --- a/builtin/providers/aws/resource_aws_elb.go +++ b/builtin/providers/aws/resource_aws_elb.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "log" + "strings" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" @@ -541,9 +542,11 @@ func resourceAwsElbListenerHash(v interface{}) int { var buf bytes.Buffer m := v.(map[string]interface{}) buf.WriteString(fmt.Sprintf("%d-", m["instance_port"].(int))) - buf.WriteString(fmt.Sprintf("%s-", m["instance_protocol"].(string))) + buf.WriteString(fmt.Sprintf("%s-", + strings.ToLower(m["instance_protocol"].(string)))) buf.WriteString(fmt.Sprintf("%d-", m["lb_port"].(int))) - buf.WriteString(fmt.Sprintf("%s-", m["lb_protocol"].(string))) + buf.WriteString(fmt.Sprintf("%s-", + strings.ToLower(m["lb_protocol"].(string)))) if v, ok := m["ssl_certificate_id"]; ok { buf.WriteString(fmt.Sprintf("%s-", v.(string))) diff --git a/builtin/providers/aws/resource_aws_elb_test.go b/builtin/providers/aws/resource_aws_elb_test.go index aca375e06..f4cdc3a96 100644 --- a/builtin/providers/aws/resource_aws_elb_test.go +++ b/builtin/providers/aws/resource_aws_elb_test.go @@ -362,6 +362,39 @@ func TestAccAWSELB_SecurityGroups(t *testing.T) { }) } +// Unit test for listeners hash +func TestResourceAwsElbListenerHash(t *testing.T) { + cases := map[string]struct { + Left map[string]interface{} + Right map[string]interface{} + Match bool + }{ + "protocols are case insensitive": { + map[string]interface{}{ + "instance_port": 80, + "instance_protocol": "TCP", + "lb_port": 80, + "lb_protocol": "TCP", + }, + map[string]interface{}{ + "instance_port": 80, + "instance_protocol": "Tcp", + "lb_port": 80, + "lb_protocol": "tcP", + }, + true, + }, + } + + for tn, tc := range cases { + leftHash := resourceAwsElbListenerHash(tc.Left) + rightHash := resourceAwsElbListenerHash(tc.Right) + if (leftHash == rightHash) != tc.Match { + t.Fatalf("%s: expected match: %t, but did not get it", tn, tc.Match) + } + } +} + func testAccCheckAWSELBDestroy(s *terraform.State) error { conn := testAccProvider.Meta().(*AWSClient).elbconn @@ -513,7 +546,8 @@ resource "aws_elb" "bar" { instance_port = 8000 instance_protocol = "http" lb_port = 80 - lb_protocol = "http" + // Protocol should be case insensitive + lb_protocol = "HttP" } tags {