From aabb200f2d5f676f4ac41d8bc48ea014e501f528 Mon Sep 17 00:00:00 2001 From: macheins Date: Thu, 7 Jul 2016 16:01:33 +0200 Subject: [PATCH] Allow empty names in aws_route53_record Added test for aws_route53_record with empty name Integrated test for aws_route53_record with empty name Changed test to use a third-level domain for zone --- .../aws/resource_aws_route53_record.go | 6 +++- .../aws/resource_aws_route53_record_test.go | 31 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/builtin/providers/aws/resource_aws_route53_record.go b/builtin/providers/aws/resource_aws_route53_record.go index 16002b4b6a..6a646335f9 100644 --- a/builtin/providers/aws/resource_aws_route53_record.go +++ b/builtin/providers/aws/resource_aws_route53_record.go @@ -695,7 +695,11 @@ func expandRecordName(name, zone string) string { rn := strings.ToLower(strings.TrimSuffix(name, ".")) zone = strings.TrimSuffix(zone, ".") if !strings.HasSuffix(rn, zone) { - rn = strings.Join([]string{name, zone}, ".") + if len(name) == 0 { + rn = zone + } else { + rn = strings.Join([]string{name, zone}, ".") + } } return rn } diff --git a/builtin/providers/aws/resource_aws_route53_record_test.go b/builtin/providers/aws/resource_aws_route53_record_test.go index 531211842d..823d1b67e9 100644 --- a/builtin/providers/aws/resource_aws_route53_record_test.go +++ b/builtin/providers/aws/resource_aws_route53_record_test.go @@ -339,6 +339,23 @@ func TestAccAWSRoute53Record_TypeChange(t *testing.T) { }) } +func TestAccAWSRoute53Record_empty(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + IDRefreshName: "aws_route53_record.empty", + Providers: testAccProviders, + CheckDestroy: testAccCheckRoute53RecordDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccRoute53RecordConfigEmptyName, + Check: resource.ComposeTestCheckFunc( + testAccCheckRoute53RecordExists("aws_route53_record.empty"), + ), + }, + }, + }) +} + func testAccCheckRoute53RecordDestroy(s *terraform.State) error { conn := testAccProvider.Meta().(*AWSClient).r53conn for _, rs := range s.RootModule().Resources { @@ -972,3 +989,17 @@ resource "aws_route53_record" "sample" { records = ["127.0.0.1", "8.8.8.8"] } ` + +const testAccRoute53RecordConfigEmptyName = ` +resource "aws_route53_zone" "main" { + name = "not.example.com" +} + +resource "aws_route53_record" "empty" { + zone_id = "${aws_route53_zone.main.zone_id}" + name = "" + type = "A" + ttl = "30" + records = ["127.0.0.1"] +} +`