diff --git a/builtin/providers/aws/resource_aws_route53_record.go b/builtin/providers/aws/resource_aws_route53_record.go index 2678385c1..7fa9aae12 100644 --- a/builtin/providers/aws/resource_aws_route53_record.go +++ b/builtin/providers/aws/resource_aws_route53_record.go @@ -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{ diff --git a/builtin/providers/aws/resource_aws_route53_record_test.go b/builtin/providers/aws/resource_aws_route53_record_test.go index f07215df5..65df31729 100644 --- a/builtin/providers/aws/resource_aws_route53_record_test.go +++ b/builtin/providers/aws/resource_aws_route53_record_test.go @@ -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"