provider/aws: Add a regression test for Route53 records

This is a follow up on #4892 with tests that demonstrate creating a record and a zone, then destroying said record, and confirming that a new plan is generated, using the ExpectNonEmptyPlan flag

This simulates the bug reported in #4641 by mimicking the state file that one would have if they created a record with Terraform v0.6.6, which is to say a weight = 0 for a default value.

When upgrading, there would be an expected plan change to get that to -1. To mimic the statefile we apply the record and then in a follow up step change the attributes directly. We then try to delete the record.

I tested this by grabbing the source of aws_resource_route53.go from Terraform v0.6.9 and running the included test, which fails. The test will pass with #4892 , because we no longer reconstruct what the record should be based on the state (instead finding via the API and elimination/matching)
This commit is contained in:
clint shryock 2016-02-02 12:37:06 -06:00
parent dce2994151
commit 53a42eaa0f
2 changed files with 59 additions and 1 deletions

View File

@ -355,7 +355,7 @@ func resourceAwsRoute53RecordDelete(d *schema.ResourceData, meta interface{}) er
}
}
// Create the new records
// Change batch for deleting
changeBatch := &route53.ChangeBatch{
Comment: aws.String("Deleted by Terraform"),
Changes: []*route53.Change{

View File

@ -258,6 +258,58 @@ func TestAccAWSRoute53Record_TypeChange(t *testing.T) {
})
}
// Test record deletion out of band and make sure we render a new plan
// Part of regression test(s) for https://github.com/hashicorp/terraform/pull/4892
func TestAccAWSRoute53Record_planUpdate(t *testing.T) {
var zone route53.GetHostedZoneOutput
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckRoute53RecordDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccRoute53RecordConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckRoute53RecordExists("aws_route53_record.default"),
testAccCheckRoute53ZoneExists("aws_route53_zone.main", &zone),
),
},
resource.TestStep{
Config: testAccRoute53RecordConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckRoute53DeleteRecord("aws_route53_record.default", &zone),
),
ExpectNonEmptyPlan: true,
},
resource.TestStep{
Config: testAccRoute53RecordNoConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckRoute53ZoneExists("aws_route53_zone.main", &zone),
),
},
},
})
}
func testAccCheckRoute53DeleteRecord(n string, zone *route53.GetHostedZoneOutput) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.Primary.ID == "" {
return fmt.Errorf("No hosted zone ID is set")
}
// Manually set the weight to 0 to replicate a record created in Terraform
// pre-0.6.9
rs.Primary.Attributes["weight"] = "0"
return nil
}
}
func testAccCheckRoute53RecordDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).r53conn
for _, rs := range s.RootModule().Resources {
@ -354,6 +406,12 @@ resource "aws_route53_record" "default" {
}
`
const testAccRoute53RecordNoConfig = `
resource "aws_route53_zone" "main" {
name = "notexample.com"
}
`
const testAccRoute53RecordConfigSuffix = `
resource "aws_route53_zone" "main" {
name = "notexample.com"