Skip to content

Conversation

@mildwonkey
Copy link
Contributor

@mildwonkey mildwonkey commented Aug 18, 2025

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 the nodeActionTriggerPlanExpand.lifecycleActionTrigger so 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 uses count.index or for_each.key) during nodeActionTriggerPlanExpand.DynamicExpand

@mildwonkey mildwonkey added the no-changelog-needed Add this to your PR if the change does not require a changelog entry label Aug 18, 2025
@mildwonkey mildwonkey force-pushed the mildwonkey/fix-action-ref branch from 794a641 to e4f8082 Compare August 18, 2025 19:06
Copy link
Contributor

@DanielMSchmidt DanielMSchmidt left a 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?

@mildwonkey
Copy link
Contributor Author

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

    --- FAIL: TestContextPlan_actions/expanded_resource_-_expanded_action (0.00s)
panic: unexpected action address addrs.CountAttr [recovered, repanicked]

@mildwonkey mildwonkey force-pushed the mildwonkey/fix-action-ref branch from 583dade to 9c1c9f2 Compare August 21, 2025 13:21
@mildwonkey mildwonkey marked this pull request as ready for review August 21, 2025 13:24
@mildwonkey mildwonkey requested a review from a team as a code owner August 21, 2025 13:24
func invalidLinkedResourceDiag(subj *hcl.Range) *hcl.Diagnostic {
return &hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: `Invalid "linked_resource"`,
Copy link
Member

@matejrisek matejrisek Aug 22, 2025

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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
DanielMSchmidt previously approved these changes Aug 22, 2025
Copy link
Contributor

@DanielMSchmidt DanielMSchmidt left a 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)
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// 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) {
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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)

@mildwonkey mildwonkey force-pushed the mildwonkey/fix-action-ref branch from 47effdc to 1ff834e Compare August 22, 2025 13:41
@mildwonkey mildwonkey merged commit 76a9aa2 into main Aug 22, 2025
7 checks passed
@mildwonkey mildwonkey deleted the mildwonkey/fix-action-ref branch August 22, 2025 15:23
@github-actions
Copy link
Contributor

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.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

no-changelog-needed Add this to your PR if the change does not require a changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants