-
Notifications
You must be signed in to change notification settings - Fork 10.1k
fix: move parsing action reference expressions into terraform #37458
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
Conversation
794a641 to
e4f8082
Compare
DanielMSchmidt
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.
Looks good to me, does this mean we can now enable this test?
Nope, but thanks for the reminder 😅 - enabling it confirmed my concerns re: additional refs and how I'm handling count/foreach in the expression |
583dade to
9c1c9f2
Compare
| func invalidLinkedResourceDiag(subj *hcl.Range) *hcl.Diagnostic { | ||
| return &hcl.Diagnostic{ | ||
| Severity: hcl.DiagError, | ||
| Summary: `Invalid "linked_resource"`, |
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.
Out of curiosity and for my learning - why remove quotation marks?
There are more such instances in this very file and I a quick search shows that we use them for this purpose in other parts of the code.
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.
I was seeing those in tests where none of the other messages had quotes around the attribute, so I removed them, but you make a good point that actually did nothing for consistency.
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.
I'll add diagnostics to the (not-yet-extant) list of things that need style guides 😁
DanielMSchmidt
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.
Looks good to me 👍 I'd like to have more test cases around scenarios we don't support (like using locals.my_action_list, concat, etc), but we can also add them in a follow up :)
| var ref *addrs.Reference | ||
| var diags tfdiags.Diagnostics | ||
|
|
||
| traversal, diags := actionExprToTraversal(expr, repData) |
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.
Wouldn't we want to validate that this is a reference to an action or action instance here or is that done somewhere else?
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.
We do, during config load: https://github.com/hashicorp/terraform/blob/main/internal/configs/action.go#L157-L163
| // expanded or fully evaluated, so we will do that now. | ||
| // Grab the instance key, necessary if the action uses [count.index] or [each.key] | ||
| repData := instances.RepetitionData{} | ||
| switch k := key.(type) { |
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.
Can't we use expander.GetResourceInstanceRepetitionData(addr addrs.AbsResourceInstance) here? The resource should have run before, because actions always plan after their triggering resource.
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.
Maybe! Most of this was copied from the replace_trigger_by evaluation code and I didn't change anything I didn't have an explicit need to change.
| actionInstanceKey addrs.InstanceKey // TODO: This should probably be a new address? Look at resources | ||
| resolvedProvider addrs.AbsProviderConfig | ||
| actionConfig *configs.Action | ||
| Addr addrs.ConfigAction |
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.
👍 on the rename, it bothered me a bit but I always forgot again before taking action (pun intended)
The switch statement isn't exhaustive, but we've already done similar during config parsing. I am absolutely open to suggestions
47effdc to
1ff834e
Compare
|
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. |
Previously, I was erroneously storing action and linkedResource expressions as Traversals during config loading. This PR replaces those fields with hcl.Expression, moves some validation around to account for the fact we don't have fully evaluated traversals yet (some checks have been removed entirely and will be replaced in a follow up PR, I wanted to get this right first), and finally moves the
I stumbled upon the jsonconfig package at some point in all this, so that first file is really just opportunistic.
To solve this, I added a permissive parsing of the ActionExpression during
ActionPlanTransformer.transformSingle(to get the config action) and store the action expression inside thenodeActionTriggerPlanExpand.lifecycleActionTriggerso it can be fully evaluated (with access to the resource's repetition data, which is necessary if the action in the resource's lifecycle block usescount.indexorfor_each.key)duringnodeActionTriggerPlanExpand.DynamicExpand