-
Notifications
You must be signed in to change notification settings - Fork 10.1k
fix: validate replace_triggered_by attribute references #38010
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
fix: validate replace_triggered_by attribute references #38010
Conversation
SarahFrench
left a comment
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.
Hi @vietcgi , thanks for your contribution!
I've left some minor comments on the changes in this PR, broadly it looks good but I have a small question around the nil/null checks.
In triage we discussed the original issue you're addressing and thought that ideally the solution would have two parts. Your proposed changes are the first part, by helping users identify when a bad reference is used during planning. Ideally users would also be able to use terraform validate to detect when their configuration has a bad reference in replace_triggered_by. This would let people identify when the defect first enters their configuration, instead of only identifying it when it first impacts a plan action. Would you be interested in implementing that second part in this PR, or separately? No worries if not, in that case I'd open a new issue for someone else to pick up.
jbardin
left a comment
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.
Hi @vietcgi,
Terraform needs to always account for resources which may contain dynamically typed values. The change proposed here would fail if those dynamically typed values were to change from one plan to the next. We can't exclude the replace_triggered_by references from traversing into dynamic types, because it's already been designed to do so. This means if we are going to have any more detailed diagnostics, those diagnostics will need to be derived from the target resource schema alone, and not rely on the current value type
7067bfe to
d68e029
Compare
|
Hi @jbardin, Thanks for the feedback. You're righ. I've updated the implementation to use schema-based validation instead of value-based validation. The fix now uses StaticValidateTraversal to validate the attribute reference against the target resource's schema, which properly handles dynamically-typed attributes. This way we only error on truly invalid references that don't exist in the schema, rather than relying on the current value type which could change between plans. |
|
Thanks @jbardin, good catch! Updated to use |
jbardin
left a comment
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.
Thanks!
Summary
replace_triggered_bynow reports an error when given an invalid attribute reference that does not exist in the target resourceTest plan
TestContext2Plan_triggeredByInvalidAttributereplace_triggered_bytests passnull_resourceconfirms invalid references now produce errorsFixes #36740