From 0c80b4d172b23fc49febd95385c84ed4310d5594 Mon Sep 17 00:00:00 2001 From: stack72 Date: Sat, 3 Sep 2016 18:14:50 +0300 Subject: [PATCH] provider/aws: Wait for `aws_route_53_record` to be in-sync after a delete MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #6679 When we change the type of a record, it forces a new resource. We never waited for the recordset to be in-sync after a deletion. ``` % make testacc TEST=./builtin/providers/aws % TESTARGS='-run=TestAccAWSRoute53Record_' % ✹ ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2016/09/03 17:55:03 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSRoute53Record_ -timeout 120m === RUN TestAccAWSRoute53Record_basic --- PASS: TestAccAWSRoute53Record_basic (85.54s) === RUN TestAccAWSRoute53Record_basic_fqdn --- PASS: TestAccAWSRoute53Record_basic_fqdn (101.75s) === RUN TestAccAWSRoute53Record_txtSupport --- PASS: TestAccAWSRoute53Record_txtSupport (84.01s) === RUN TestAccAWSRoute53Record_spfSupport --- PASS: TestAccAWSRoute53Record_spfSupport (85.08s) === RUN TestAccAWSRoute53Record_generatesSuffix --- PASS: TestAccAWSRoute53Record_generatesSuffix (97.12s) === RUN TestAccAWSRoute53Record_wildcard --- PASS: TestAccAWSRoute53Record_wildcard (141.08s) === RUN TestAccAWSRoute53Record_failover --- PASS: TestAccAWSRoute53Record_failover (91.25s) === RUN TestAccAWSRoute53Record_weighted_basic --- PASS: TestAccAWSRoute53Record_weighted_basic (89.01s) === RUN TestAccAWSRoute53Record_alias --- PASS: TestAccAWSRoute53Record_alias (88.91s) === RUN TestAccAWSRoute53Record_s3_alias --- PASS: TestAccAWSRoute53Record_s3_alias (103.10s) === RUN TestAccAWSRoute53Record_weighted_alias --- PASS: TestAccAWSRoute53Record_weighted_alias (174.71s) === RUN TestAccAWSRoute53Record_geolocation_basic --- PASS: TestAccAWSRoute53Record_geolocation_basic (89.50s) === RUN TestAccAWSRoute53Record_latency_basic --- PASS: TestAccAWSRoute53Record_latency_basic (89.12s) === RUN TestAccAWSRoute53Record_TypeChange --- PASS: TestAccAWSRoute53Record_TypeChange (138.09s) === RUN TestAccAWSRoute53Record_empty --- PASS: TestAccAWSRoute53Record_empty (88.51s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 1684.774s ``` --- .../aws/resource_aws_route53_record.go | 13 ++++++++- .../aws/resource_aws_route53_record_test.go | 29 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/builtin/providers/aws/resource_aws_route53_record.go b/builtin/providers/aws/resource_aws_route53_record.go index 92db6bc33..8a5b5c92d 100644 --- a/builtin/providers/aws/resource_aws_route53_record.go +++ b/builtin/providers/aws/resource_aws_route53_record.go @@ -528,7 +528,18 @@ func resourceAwsRoute53RecordDelete(d *schema.ResourceData, meta interface{}) er ChangeBatch: changeBatch, } - _, err = deleteRoute53RecordSet(conn, req) + respRaw, err := deleteRoute53RecordSet(conn, req) + if err != nil { + return errwrap.Wrapf("[ERR]: Error building changeset: {{err}}", err) + } + + changeInfo := respRaw.(*route53.ChangeResourceRecordSetsOutput).ChangeInfo + + err = waitForRoute53RecordSetToSync(conn, cleanChangeID(*changeInfo.Id)) + if err != nil { + return err + } + return err } diff --git a/builtin/providers/aws/resource_aws_route53_record_test.go b/builtin/providers/aws/resource_aws_route53_record_test.go index 5ec466b7c..667337abc 100644 --- a/builtin/providers/aws/resource_aws_route53_record_test.go +++ b/builtin/providers/aws/resource_aws_route53_record_test.go @@ -454,6 +454,35 @@ resource "aws_route53_record" "default" { records = ["127.0.0.1", "127.0.0.27"] } ` + +const testAccRoute53RecordConfigCNAMERecord = ` +resource "aws_route53_zone" "main" { + name = "notexample.com" +} + +resource "aws_route53_record" "default" { + zone_id = "${aws_route53_zone.main.zone_id}" + name = "host123.domain" + type = "CNAME" + ttl = "30" + records = ["1.2.3.4"] +} +` + +const testAccRoute53RecordConfigCNAMERecordUpdateToCNAME = ` +resource "aws_route53_zone" "main" { + name = "notexample.com" +} + +resource "aws_route53_record" "default" { + zone_id = "${aws_route53_zone.main.zone_id}" + name = "host123.domain" + type = "A" + ttl = "30" + records = ["1.2.3.4"] +} +` + const testAccRoute53RecordConfig_fqdn = ` resource "aws_route53_zone" "main" { name = "notexample.com"