Merge pull request #4958 from hashicorp/b-aws-r53-record-tests

provider/aws: Add a regression test for Route53 records
This commit is contained in:
Clint 2016-02-11 13:32:29 -06:00
commit e04450d95f
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"