-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
provider/aws: Refactor Route53 record to fix regression in deleting #4892
Conversation
refactored to add a `findRecord` method to find the matching record set, and use that for the `DELETE` method call.
if err != nil { | ||
log.Printf("[DEBUG] No matching record found for: %s, removing from state file", d.Id()) | ||
d.SetId("") | ||
return err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like any kind of error here is treated the same. Up in findRecord
there's code to recognize NoSuchHostedZone
specifically, but then it's wrapped back up in a regular error
return value.
I believe this would mean that, for example, if ran terraform plan
w/o network connectivity, I could lose all my R53 records from the state.
Maybe we can change the "NoSuchHostedZone"
case to just return nil
, nil
and switch this up to something like:
if err != nil {
return err
}
if rec == nil {
log.Printf("[WARN] No matching record found...")
d.SetId("")
}
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree; this was refactored in 3bbb21d
Switching to |
Changes to error handling LGTM. Build is because of broken upstream dep rather than anything on this PR. |
provider/aws: Refactor Route53 record to fix regression in deleting
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)
Please get this in 0.6.12. This is a PITA. |
This is a follow up on hashicorp#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 hashicorp#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 hashicorp#4892 , because we no longer reconstruct what the record should be based on the state (instead finding via the API and elimination/matching)
This is a follow up on hashicorp#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 hashicorp#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 hashicorp#4892 , because we no longer reconstruct what the record should be based on the state (instead finding via the API and elimination/matching)
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Route 53 records created in Terraform versions pre-0.6.9 can not be deleted by versions post-0.6.9. This is because of the addition of the
weight
attribute and how we calculate our records for changes after introducing the sentinel value of-1
for weights:Records created pre-0.6.9 do not have the
weight
sentinel value of-1
, which was added so that a value of zero could be used for the weight (prior to this it could not be). Because they do not have the-1
value, ad.Get("weight")
call returns0
, which is greater than-1
. As a result,delete
commands includes a0
weight on records that don't have a weight, so thedelete
record set doesn't match.Since the actual record is not a thing we can query directly (it’s a property of the zone), we can’t just issue a DELETE to a specific record, we have to isolate it from the zone’s records and send an UPDATE / DELETE
ChangeBatch
call to the zone. Currently, we do this by rebuilding the record set from the state.Additions to the state (via new attributes, et. al) in new versions of Terraform can cause this rebuild to be different than a previous run, if the state file was created in a previous version of Terraform.
In this PR we refactor out the code used in the
READ
method to range over a record set and find the matching record. We can then issue a delete call on that record, or update the local state file if we’re in theREAD
method.Fixes #4641