diff --git a/aws/resource_aws_route53_record.go b/aws/resource_aws_route53_record.go index 719825ffec5..d3c414b7714 100644 --- a/aws/resource_aws_route53_record.go +++ b/aws/resource_aws_route53_record.go @@ -101,6 +101,9 @@ func resourceAwsRoute53Record() *schema.Resource { Type: schema.TypeString, Required: true, StateFunc: normalizeAwsAliasName, + DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { + return strings.ToLower(old) == strings.ToLower(new) + }, }, "evaluate_target_health": { @@ -898,11 +901,11 @@ func nilString(s string) *string { func normalizeAwsAliasName(alias interface{}) string { input := alias.(string) - if strings.HasPrefix(input, "dualstack.") { - return strings.Replace(input, "dualstack.", "", -1) + output := strings.ToLower(input) + if strings.HasPrefix(output, "dualstack.") { + output = strings.TrimLeft(output, "dualstack.") } - - return strings.TrimRight(input, ".") + return strings.TrimRight(output, ".") } func parseRecordId(id string) [4]string { diff --git a/aws/resource_aws_route53_record_test.go b/aws/resource_aws_route53_record_test.go index 996f31bd081..317fa0b83cd 100644 --- a/aws/resource_aws_route53_record_test.go +++ b/aws/resource_aws_route53_record_test.go @@ -52,6 +52,24 @@ func TestExpandRecordName(t *testing.T) { } } +func TestNormalizeAwsAliasName(t *testing.T) { + cases := []struct { + Input, Output string + }{ + {"www.nonexample.com", "www.nonexample.com"}, + {"www.nonexample.com.", "www.nonexample.com"}, + {"dualstack.name-123456789.region.elb.amazonaws.com", "name-123456789.region.elb.amazonaws.com"}, + {"NAME-123456789.region.elb.amazonaws.com", "name-123456789.region.elb.amazonaws.com"}, + } + + for _, tc := range cases { + actual := normalizeAwsAliasName(tc.Input) + if actual != tc.Output { + t.Fatalf("input: %s\noutput: %s", tc.Input, actual) + } + } +} + func TestParseRecordId(t *testing.T) { cases := []struct { Input, Zone, Name, Type, Set string @@ -280,6 +298,25 @@ func TestAccAWSRoute53Record_alias(t *testing.T) { }) } +func TestAccAWSRoute53Record_aliasUppercase(t *testing.T) { + rs := acctest.RandString(10) + config := fmt.Sprintf(testAccRoute53ElbAliasRecordUppercase, rs) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + IDRefreshName: "aws_route53_record.alias", + Providers: testAccProviders, + CheckDestroy: testAccCheckRoute53RecordDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: config, + Check: resource.ComposeTestCheckFunc( + testAccCheckRoute53RecordExists("aws_route53_record.alias"), + ), + }, + }, + }) +} + func TestAccAWSRoute53Record_s3_alias(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -968,6 +1005,36 @@ resource "aws_elb" "main" { } ` +const testAccRoute53ElbAliasRecordUppercase = ` +resource "aws_route53_zone" "main" { + name = "notexample.com" +} + +resource "aws_route53_record" "alias" { + zone_id = "${aws_route53_zone.main.zone_id}" + name = "www" + type = "A" + + alias { + zone_id = "${aws_elb.main.zone_id}" + name = "${aws_elb.main.dns_name}" + evaluate_target_health = true + } +} + +resource "aws_elb" "main" { + name = "FOOBAR-TERRAFORM-ELB-%s" + availability_zones = ["us-west-2a"] + + listener { + instance_port = 80 + instance_protocol = "http" + lb_port = 80 + lb_protocol = "http" + } +} +` + const testAccRoute53AliasRecord = ` resource "aws_route53_zone" "main" { name = "notexample.com"