Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resource aws_route53_zone - count fix #4341

Merged
merged 1 commit into from
Apr 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aws/resource_aws_route53_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func resourceAwsRoute53ZoneCreate(d *schema.ResourceData, meta interface{}) erro
req := &route53.CreateHostedZoneInput{
Name: aws.String(d.Get("name").(string)),
HostedZoneConfig: &route53.HostedZoneConfig{Comment: aws.String(d.Get("comment").(string))},
CallerReference: aws.String(time.Now().Format(time.RFC3339Nano)),
CallerReference: aws.String(d.Get("name").(string) + time.Now().Format(time.RFC3339Nano)),
}
if v := d.Get("vpc_id"); v != "" {
req.VPC = &route53.VPC{
Expand Down
39 changes: 38 additions & 1 deletion aws/resource_aws_route53_zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestCleanChangeID(t *testing.T) {
}

func TestAccAWSRoute53Zone_basic(t *testing.T) {
var zone route53.GetHostedZoneOutput
var zone, zone0, zone1, zone2, zone3, zone4 route53.GetHostedZoneOutput
var td route53.ResourceTagSet

rString := acctest.RandString(8)
Expand All @@ -86,6 +86,21 @@ func TestAccAWSRoute53Zone_basic(t *testing.T) {
testAccCheckTagsR53(&td.Tags, "foo", "bar"),
),
},
resource.TestStep{
Config: testAccRoute53ZoneCountConfig(),
Check: resource.ComposeTestCheckFunc(
testAccCheckRoute53ZoneExists("aws_route53_zone.main.0", &zone0),
testAccCheckDomainName(&zone0, "subdomain0.terraformtest.com."),
testAccCheckRoute53ZoneExists("aws_route53_zone.main.1", &zone1),
testAccCheckDomainName(&zone1, "subdomain1.terraformtest.com."),
testAccCheckRoute53ZoneExists("aws_route53_zone.main.2", &zone2),
testAccCheckDomainName(&zone2, "subdomain2.terraformtest.com."),
testAccCheckRoute53ZoneExists("aws_route53_zone.main.3", &zone3),
testAccCheckDomainName(&zone3, "subdomain3.terraformtest.com."),
testAccCheckRoute53ZoneExists("aws_route53_zone.main.4", &zone4),
testAccCheckDomainName(&zone4, "subdomain4.terraformtest.com."),
),
},
},
})
}
Expand Down Expand Up @@ -373,7 +388,19 @@ func testAccLoadTagsR53(zone *route53.GetHostedZoneOutput, td *route53.ResourceT
return nil
}
}
func testAccCheckDomainName(zone *route53.GetHostedZoneOutput, domain string) resource.TestCheckFunc {
return func(s *terraform.State) error {
if zone.HostedZone.Name == nil {
return fmt.Errorf("Empty name in HostedZone for domain %s", domain)
}

if *zone.HostedZone.Name == domain {
return nil
}

return fmt.Errorf("Invalid domain name. Expected %s is %s", domain, *zone.HostedZone.Name)
}
}
func testAccRoute53ZoneConfig(zoneName string) string {
return fmt.Sprintf(`
resource "aws_route53_zone" "main" {
Expand All @@ -388,6 +415,16 @@ resource "aws_route53_zone" "main" {
`, zoneName)
}

func testAccRoute53ZoneCountConfig() string {
return fmt.Sprintf(`
resource "aws_route53_zone" "main" {
name = "subdomain${count.index}.terraformtest.com"

count = 5
}
`)
}

func testAccRoute53ZoneConfig_forceDestroy(zoneName1, zoneName2 string) string {
return fmt.Sprintf(`
resource "aws_route53_zone" "destroyable" {
Expand Down