Merge branch 'macheins-empty-name-in-aws-route53-records'
This commit is contained in:
commit
1c07582990
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
@ -351,9 +368,11 @@ func testAccCheckRoute53RecordDestroy(s *terraform.State) error {
|
|||
name := parts[1]
|
||||
rType := parts[2]
|
||||
|
||||
en := expandRecordName(name, "notexample.com")
|
||||
|
||||
lopts := &route53.ListResourceRecordSetsInput{
|
||||
HostedZoneId: aws.String(cleanZoneID(zone)),
|
||||
StartRecordName: aws.String(name),
|
||||
StartRecordName: aws.String(en),
|
||||
StartRecordType: aws.String(rType),
|
||||
}
|
||||
|
||||
|
@ -410,6 +429,7 @@ func testAccCheckRoute53RecordExists(n string) resource.TestCheckFunc {
|
|||
if len(resp.ResourceRecordSets) == 0 {
|
||||
return fmt.Errorf("Record does not exist")
|
||||
}
|
||||
|
||||
// rec := resp.ResourceRecordSets[0]
|
||||
for _, rec := range resp.ResourceRecordSets {
|
||||
recName := cleanRecordName(*rec.Name)
|
||||
|
@ -972,3 +992,17 @@ resource "aws_route53_record" "sample" {
|
|||
records = ["127.0.0.1", "8.8.8.8"]
|
||||
}
|
||||
`
|
||||
|
||||
const testAccRoute53RecordConfigEmptyName = `
|
||||
resource "aws_route53_zone" "main" {
|
||||
name = "notexample.com"
|
||||
}
|
||||
|
||||
resource "aws_route53_record" "empty" {
|
||||
zone_id = "${aws_route53_zone.main.zone_id}"
|
||||
name = ""
|
||||
type = "A"
|
||||
ttl = "30"
|
||||
records = ["127.0.0.1"]
|
||||
}
|
||||
`
|
||||
|
|
Loading…
Reference in New Issue