fix: use old zone id for records removal #45242
Open
+61
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Rollback Plan
If a change needs to be reverted, we will publish an updated version of the library.
Changes to Security Controls
No changes to security controls (access controls, encryption, logging) in this pull request.
Description
Fixes a bug in Route53 hosted zone deletion logic during ForceNew operations when the zone name is updated. The issue occurred because the deletion process was using the new zone name from Terraform state instead of the actual zone name being deleted, causing NS/SOA record filtering to fail.
Key Changes:
deleteHostedZonefunction to fetch the actual zone name from AWS API instead of relying on Terraform state during ForceNew operationsTestAccRoute53Zone_nameUpdateto verify zone recreation behavior when name changestestAccCheckZoneRecreatedto validate zone recreation in testsBug Details:
During ForceNew operations (e.g., when changing the zone name), Terraform state contains the new zone name while the old zone still exists with the original name. The deletion logic was incorrectly using the new zone name from state to filter NS/SOA records, causing the filtering to fail and attempt deletion of undeletable apex records.
Root Cause:
When a Route53 zone name is changed, Terraform triggers a ForceNew operation that:
force_destroy = trueDuring step 2, the Terraform state already contains the new zone name, but the actual zone being deleted still has the old name. The
deleteAllResourceRecordsFromHostedZonefunction was using the zone name from Terraform state (new name) to filter NS/SOA records, but the actual records in the zone being deleted still used the old zone name. This mismatch caused the filtering logic to fail, leading to attempts to delete undeletable NS/SOA records.Solution:
Modified the
deleteHostedZonefunction to fetch the actual zone name from AWS using theGetHostedZoneAPI call before proceeding with record deletion. This ensures the correct zone name is used for NS/SOA record filtering regardless of Terraform state values.Testing:
Error Fixed:
References
Closes #45241
Output from Acceptance Testing