[bug] Fix inconsistent final plan for tgw association/propagation #44542
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
Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.
Description
Forensic Report: Transit Gateway Route Table Association/Propagation ForceNew Behavior
Executive Summary
This report documents the history of
ForceNew
behavior changes inaws_ec2_transit_gateway_route_table_association
andaws_ec2_transit_gateway_route_table_propagation
resources, the problems they attempted to solve, the new problems they created, and justification for reverting the changes.Timeline of Events
Original State (Pre-v5.87.0)
transit_gateway_attachment_id
hadForceNew: true
March 2023: Issue #30085 Reported
allowed_prefixes
onaws_dx_gateway_association
caused unnecessary recreation ofaws_ec2_transit_gateway_route_table_association
aws_ec2_transit_gateway_dx_gateway_attachment
to get attachment IDaws_dx_gateway_association.allowed_prefixes
changed, Terraform deferred the data source read to apply timetransit_gateway_attachment_id
unknown during planningForceNew: true
on unknown value triggered replacementApril 2024: Issue #36889 Reported
February 2025: PR #41292 - First Workaround Attempt
aws_ec2_transit_gateway_route_table_association
ForceNew: true
fromtransit_gateway_attachment_id
CustomizeDiff
logic to conditionally applyForceNew
July 2025: PR #43405 - Second Workaround Attempt
aws_ec2_transit_gateway_route_table_propagation
CustomizeDiff
logic from PR Avoid recreating aws_ec2_transit_gateway_route_table_association when unnecessary #41292July 2025: PR #43436 - Proper Solution for DX Gateway
aws_dx_gateway_association
transit_gateway_attachment_id
attributeAugust 2025: Issue #43706 Reported
CustomizeDiff
workaround logic is fundamentally flawedCustomizeDiff
logic incorrectly assumes it won't changeTechnical Analysis
The Fundamental Flaw
The
CustomizeDiff
logic attempts to distinguish between two scenarios:Scenario A (Intended to handle):
Scenario B (Fails to handle):
The logic cannot distinguish between these scenarios because both present identically during planning:
Why the Logic Fails
The condition that allows update-in-place:
This assumption is incorrect when the attachment resource itself is being replaced.
Breaking Change Justification
Is Restoring ForceNew a Breaking Change?
Technically: Yes. Changing from non-ForceNew to ForceNew is considered breaking because it changes resource replacement behavior.
Practically: No, for the following reasons:
1. The Current Behavior is Broken
The
CustomizeDiff
workaround produces incorrect plans that fail during apply with "inconsistent final plan" errors. This is not a working feature - it's a bug that causes:2. Limited Actual Impact
The
CustomizeDiff
logic only prevents ForceNew in very specific conditions:In most real-world scenarios, the logic still forces recreation. The only scenarios where it prevents recreation are:
For Scenario B, users would need to be:
This is a narrow use case.
3. The Workaround Was Short-Lived
The workaround has not been in place long enough for widespread adoption.
4. The Proper Solution Exists
PR #43436 (v6.5.0) provided the correct solution for DX Gateway scenarios by exposing
transit_gateway_attachment_id
directly onaws_dx_gateway_association
. Users should migrate to using this attribute instead of data source lookups.For VPC attachments, the attachment ID is already available as the resource's
id
attribute, so no data source is needed.5. Reverting Prevents Data Loss
The current behavior can cause:
Restoring
ForceNew: true
may cause unnecessary recreations in some edge cases, but it will never cause the "inconsistent final plan" error or leave resources in a destroyed state.Recommendation
Revert the CustomizeDiff workaround and restore ForceNew: true because:
Migration Path for Users
For DX Gateway Users (Scenario A)
Before (using data source):
After (using direct attribute - requires v6.5.0+):
For VPC Attachment Users
Correct approach (no data source needed):
Conclusion
Restoring
ForceNew: true
is justified as a bug fix rather than a breaking change because:The lesson learned: Expose computed attributes directly rather than attempting to predict when unknown values will change.
Relations
Closes #43706
References
Output from Acceptance Testing