From a5dade523b4711ed7965aca4f9eb8f5db3183cc9 Mon Sep 17 00:00:00 2001 From: Kristin Laemmert Date: Mon, 23 Feb 2026 15:06:00 -0500 Subject: [PATCH 1/2] renaming action-related nodes --- internal/terraform/graph_builder_apply.go | 4 +- internal/terraform/graph_builder_plan.go | 4 +- internal/terraform/node_action.go | 16 +++---- internal/terraform/node_action_abstract.go | 2 +- internal/terraform/node_action_instance.go | 26 +++++------ .../terraform/node_action_trigger_abstract.go | 43 ++++++++----------- .../terraform/node_action_trigger_apply.go | 14 +++--- .../terraform/node_action_trigger_plan.go | 34 +++++++-------- internal/terraform/transform_action_diff.go | 6 +-- .../transform_action_trigger_config.go | 4 +- internal/terraform/transform_provider.go | 11 ++--- 11 files changed, 79 insertions(+), 85 deletions(-) diff --git a/internal/terraform/graph_builder_apply.go b/internal/terraform/graph_builder_apply.go index 71645ce98a..fba4f8a16f 100644 --- a/internal/terraform/graph_builder_apply.go +++ b/internal/terraform/graph_builder_apply.go @@ -167,9 +167,9 @@ func (b *ApplyGraphBuilder) Steps() []GraphTransformer { Operation: b.Operation, ActionTargets: b.ActionTargets, - ConcreteActionTriggerNodeFunc: func(node *nodeAbstractActionTriggerExpand, timing RelativeActionTiming) dag.Vertex { + ConcreteActionTriggerNodeFunc: func(node *nodeAbstractActionTrigger, timing RelativeActionTiming) dag.Vertex { return &nodeActionTriggerApplyExpand{ - nodeAbstractActionTriggerExpand: node, + nodeAbstractActionTrigger: node, relativeTiming: timing, } diff --git a/internal/terraform/graph_builder_plan.go b/internal/terraform/graph_builder_plan.go index b9f3f0338e..e7b7525fb8 100644 --- a/internal/terraform/graph_builder_plan.go +++ b/internal/terraform/graph_builder_plan.go @@ -178,9 +178,9 @@ func (b *PlanGraphBuilder) Steps() []GraphTransformer { ActionTargets: b.ActionTargets, queryPlanMode: b.queryPlan, - ConcreteActionTriggerNodeFunc: func(node *nodeAbstractActionTriggerExpand, _ RelativeActionTiming) dag.Vertex { + ConcreteActionTriggerNodeFunc: func(node *nodeAbstractActionTrigger, _ RelativeActionTiming) dag.Vertex { return &nodeActionTriggerPlanExpand{ - nodeAbstractActionTriggerExpand: node, + nodeAbstractActionTrigger: node, } }, }, diff --git a/internal/terraform/node_action.go b/internal/terraform/node_action.go index ca2fb1fff3..21fe3cd030 100644 --- a/internal/terraform/node_action.go +++ b/internal/terraform/node_action.go @@ -15,21 +15,21 @@ type GraphNodeConfigAction interface { ActionAddr() addrs.ConfigAction } -// nodeExpandActionDeclaration represents an action config block in a configuration module, -// which has not yet been expanded. -type nodeExpandActionDeclaration struct { +// nodeExpandAction represents an action config block in a module, which has not +// yet been expanded. +type nodeExpandAction struct { *NodeAbstractAction } var ( - _ GraphNodeDynamicExpandable = (*nodeExpandActionDeclaration)(nil) + _ GraphNodeDynamicExpandable = (*nodeExpandAction)(nil) ) -func (n *nodeExpandActionDeclaration) Name() string { +func (n *nodeExpandAction) Name() string { return n.Addr.String() + " (expand)" } -func (n *nodeExpandActionDeclaration) DynamicExpand(ctx EvalContext) (*Graph, tfdiags.Diagnostics) { +func (n *nodeExpandAction) DynamicExpand(ctx EvalContext) (*Graph, tfdiags.Diagnostics) { var g Graph var diags tfdiags.Diagnostics expander := ctx.InstanceExpander() @@ -83,7 +83,7 @@ func (n *nodeExpandActionDeclaration) DynamicExpand(ctx EvalContext) (*Graph, tf // Expand the action instances for this module. for _, knownInstKey := range knownInstKeys { - node := NodeActionDeclarationInstance{ + node := NodeAbstractActionInstance{ Addr: absActAddr.Instance(knownInstKey), Config: &n.Config, Schema: n.Schema, @@ -99,7 +99,7 @@ func (n *nodeExpandActionDeclaration) DynamicExpand(ctx EvalContext) (*Graph, tf return &g, diags } -func (n *nodeExpandActionDeclaration) recordActionData(ctx EvalContext, addr addrs.AbsAction) (diags tfdiags.Diagnostics) { +func (n *nodeExpandAction) recordActionData(ctx EvalContext, addr addrs.AbsAction) (diags tfdiags.Diagnostics) { // We'll record our expansion decision in the shared "expander" object // so that later operations (i.e. DynamicExpand and expression evaluation) diff --git a/internal/terraform/node_action_abstract.go b/internal/terraform/node_action_abstract.go index 466d1a7d76..9326cdd0a6 100644 --- a/internal/terraform/node_action_abstract.go +++ b/internal/terraform/node_action_abstract.go @@ -47,7 +47,7 @@ type ConcreteActionNodeFunc func(*NodeAbstractAction) dag.Vertex // DefaultConcreteActionNodeFunc is the default ConcreteActionNodeFunc used by // everything except validate. func DefaultConcreteActionNodeFunc(a *NodeAbstractAction) dag.Vertex { - return &nodeExpandActionDeclaration{ + return &nodeExpandAction{ NodeAbstractAction: a, } } diff --git a/internal/terraform/node_action_instance.go b/internal/terraform/node_action_instance.go index 0e6df04190..26f14055e3 100644 --- a/internal/terraform/node_action_instance.go +++ b/internal/terraform/node_action_instance.go @@ -13,12 +13,12 @@ import ( "github.com/hashicorp/terraform/internal/tfdiags" ) -// NodeActionDeclarationInstance represents an action in a particular module. +// NodeAbstractActionInstance represents an action in a particular module. // -// Action Declarations don't do anything by themselves, they are just +// Action configuration blocks don't do anything by themselves, they are just // coming into effect when they are triggered. We expand them here so that // when they are referenced we can get the configuration for the action directly. -type NodeActionDeclarationInstance struct { +type NodeAbstractActionInstance struct { Addr addrs.AbsActionInstance Config *configs.Action Schema *providers.ActionSchema @@ -27,21 +27,21 @@ type NodeActionDeclarationInstance struct { } var ( - _ GraphNodeModuleInstance = (*NodeActionDeclarationInstance)(nil) - _ GraphNodeExecutable = (*NodeActionDeclarationInstance)(nil) - _ GraphNodeReferencer = (*NodeActionDeclarationInstance)(nil) - _ GraphNodeReferenceable = (*NodeActionDeclarationInstance)(nil) + _ GraphNodeModuleInstance = (*NodeAbstractActionInstance)(nil) + _ GraphNodeExecutable = (*NodeAbstractActionInstance)(nil) + _ GraphNodeReferencer = (*NodeAbstractActionInstance)(nil) + _ GraphNodeReferenceable = (*NodeAbstractActionInstance)(nil) ) -func (n *NodeActionDeclarationInstance) Name() string { +func (n *NodeAbstractActionInstance) Name() string { return n.Addr.String() } -func (n *NodeActionDeclarationInstance) Path() addrs.ModuleInstance { +func (n *NodeAbstractActionInstance) Path() addrs.ModuleInstance { return n.Addr.Module } -func (n *NodeActionDeclarationInstance) Execute(ctx EvalContext, _ walkOperation) tfdiags.Diagnostics { +func (n *NodeAbstractActionInstance) Execute(ctx EvalContext, _ walkOperation) tfdiags.Diagnostics { var diags tfdiags.Diagnostics deferrals := ctx.Deferrals() @@ -85,12 +85,12 @@ func (n *NodeActionDeclarationInstance) Execute(ctx EvalContext, _ walkOperation } // GraphNodeReferenceable -func (n *NodeActionDeclarationInstance) ReferenceableAddrs() []addrs.Referenceable { +func (n *NodeAbstractActionInstance) ReferenceableAddrs() []addrs.Referenceable { return []addrs.Referenceable{n.Addr.Action, n.Addr.Action.Action} } // GraphNodeReferencer -func (n *NodeActionDeclarationInstance) References() []*addrs.Reference { +func (n *NodeAbstractActionInstance) References() []*addrs.Reference { var result []*addrs.Reference c := n.Config countRefs, _ := langrefs.ReferencesInExpr(addrs.ParseRef, c.Count) @@ -106,6 +106,6 @@ func (n *NodeActionDeclarationInstance) References() []*addrs.Reference { return result } -func (n *NodeActionDeclarationInstance) ModulePath() addrs.Module { +func (n *NodeAbstractActionInstance) ModulePath() addrs.Module { return n.Addr.Module.Module() } diff --git a/internal/terraform/node_action_trigger_abstract.go b/internal/terraform/node_action_trigger_abstract.go index 12c1ede969..8707303e45 100644 --- a/internal/terraform/node_action_trigger_abstract.go +++ b/internal/terraform/node_action_trigger_abstract.go @@ -23,17 +23,17 @@ const ( // ConcreteActionTriggerNodeFunc is a callback type used to convert an // abstract action trigger to a concrete one of some type. -type ConcreteActionTriggerNodeFunc func(*nodeAbstractActionTriggerExpand, RelativeActionTiming) dag.Vertex +type ConcreteActionTriggerNodeFunc func(*nodeAbstractActionTrigger, RelativeActionTiming) dag.Vertex -type nodeAbstractActionTriggerExpand struct { +type nodeAbstractActionTrigger struct { Addr addrs.ConfigAction resolvedProvider addrs.AbsProviderConfig Config *configs.Action - lifecycleActionTrigger *lifecycleActionTrigger + triggerConfig *actionTriggerConfig } -type lifecycleActionTrigger struct { +type actionTriggerConfig struct { resourceAddress addrs.ConfigResource events []configs.ActionTriggerEvent actionTriggerBlockIndex int @@ -43,50 +43,43 @@ type lifecycleActionTrigger struct { conditionExpr hcl.Expression } -func (at *lifecycleActionTrigger) Name() string { +func (at *actionTriggerConfig) Name() string { return fmt.Sprintf("%s.lifecycle.action_trigger[%d].actions[%d]", at.resourceAddress.String(), at.actionTriggerBlockIndex, at.actionListIndex) } var ( - _ GraphNodeReferencer = (*nodeAbstractActionTriggerExpand)(nil) - _ GraphNodeProviderConsumer = (*nodeAbstractActionTriggerExpand)(nil) - _ GraphNodeModulePath = (*nodeAbstractActionTriggerExpand)(nil) + _ GraphNodeReferencer = (*nodeAbstractActionTrigger)(nil) + _ GraphNodeProviderConsumer = (*nodeAbstractActionTrigger)(nil) + _ GraphNodeModulePath = (*nodeAbstractActionTrigger)(nil) ) -func (n *nodeAbstractActionTriggerExpand) Name() string { - triggeredBy := "triggered by " - if n.lifecycleActionTrigger != nil { - triggeredBy += n.lifecycleActionTrigger.resourceAddress.String() - } else { - triggeredBy += "unknown" - } - - return fmt.Sprintf("%s %s", n.Addr.String(), triggeredBy) +func (n *nodeAbstractActionTrigger) Name() string { + return fmt.Sprintf("%s triggered by %s", n.Addr.String(), n.triggerConfig.resourceAddress.String()) } -func (n *nodeAbstractActionTriggerExpand) ModulePath() addrs.Module { +func (n *nodeAbstractActionTrigger) ModulePath() addrs.Module { return n.Addr.Module } -func (n *nodeAbstractActionTriggerExpand) References() []*addrs.Reference { +func (n *nodeAbstractActionTrigger) References() []*addrs.Reference { var refs []*addrs.Reference refs = append(refs, &addrs.Reference{ Subject: n.Addr.Action, }) - if n.lifecycleActionTrigger != nil { + if n.triggerConfig != nil { refs = append(refs, &addrs.Reference{ - Subject: n.lifecycleActionTrigger.resourceAddress.Resource, + Subject: n.triggerConfig.resourceAddress.Resource, }) - conditionRefs, _ := langrefs.ReferencesInExpr(addrs.ParseRef, n.lifecycleActionTrigger.conditionExpr) + conditionRefs, _ := langrefs.ReferencesInExpr(addrs.ParseRef, n.triggerConfig.conditionExpr) refs = append(refs, conditionRefs...) } return refs } -func (n *nodeAbstractActionTriggerExpand) ProvidedBy() (addr addrs.ProviderConfig, exact bool) { +func (n *nodeAbstractActionTrigger) ProvidedBy() (addr addrs.ProviderConfig, exact bool) { if n.resolvedProvider.Provider.Type != "" { return n.resolvedProvider, true } @@ -99,10 +92,10 @@ func (n *nodeAbstractActionTriggerExpand) ProvidedBy() (addr addrs.ProviderConfi }, false } -func (n *nodeAbstractActionTriggerExpand) Provider() (provider addrs.Provider) { +func (n *nodeAbstractActionTrigger) Provider() (provider addrs.Provider) { return n.Config.Provider } -func (n *nodeAbstractActionTriggerExpand) SetProvider(config addrs.AbsProviderConfig) { +func (n *nodeAbstractActionTrigger) SetProvider(config addrs.AbsProviderConfig) { n.resolvedProvider = config } diff --git a/internal/terraform/node_action_trigger_apply.go b/internal/terraform/node_action_trigger_apply.go index faf58824d3..f639896907 100644 --- a/internal/terraform/node_action_trigger_apply.go +++ b/internal/terraform/node_action_trigger_apply.go @@ -14,7 +14,7 @@ import ( ) type nodeActionTriggerApplyExpand struct { - *nodeAbstractActionTriggerExpand + *nodeAbstractActionTrigger actionInvocationInstances []*plans.ActionInvocationInstanceSrc relativeTiming RelativeActionTiming @@ -28,14 +28,14 @@ var ( ) func (n *nodeActionTriggerApplyExpand) Name() string { - return fmt.Sprintf("%s (apply - %s)", n.nodeAbstractActionTriggerExpand.Name(), n.relativeTiming) + return fmt.Sprintf("%s (apply - %s)", n.nodeAbstractActionTrigger.Name(), n.relativeTiming) } func (n *nodeActionTriggerApplyExpand) DynamicExpand(ctx EvalContext) (*Graph, tfdiags.Diagnostics) { var g Graph var diags tfdiags.Diagnostics - if n.lifecycleActionTrigger == nil { + if n.triggerConfig == nil { panic("Only actions triggered by plan and apply are supported") } @@ -45,8 +45,8 @@ func (n *nodeActionTriggerApplyExpand) DynamicExpand(ctx EvalContext) (*Graph, t node := &nodeActionTriggerApplyInstance{ ActionInvocation: ai, resolvedProvider: n.resolvedProvider, - ActionTriggerRange: n.lifecycleActionTrigger.invokingSubject.Ptr(), - ConditionExpr: n.lifecycleActionTrigger.conditionExpr, + ActionTriggerRange: n.triggerConfig.invokingSubject.Ptr(), + ConditionExpr: n.triggerConfig.conditionExpr, } g.Add(node) invocationMap[ai] = node @@ -75,8 +75,8 @@ func (n *nodeActionTriggerApplyExpand) References() []*addrs.Reference { Subject: n.Addr.Action, }) - if n.lifecycleActionTrigger != nil { - conditionRefs, _ := langrefs.ReferencesInExpr(addrs.ParseRef, n.lifecycleActionTrigger.conditionExpr) + if n.triggerConfig != nil { + conditionRefs, _ := langrefs.ReferencesInExpr(addrs.ParseRef, n.triggerConfig.conditionExpr) refs = append(refs, conditionRefs...) } diff --git a/internal/terraform/node_action_trigger_plan.go b/internal/terraform/node_action_trigger_plan.go index a27615d471..5bc25853db 100644 --- a/internal/terraform/node_action_trigger_plan.go +++ b/internal/terraform/node_action_trigger_plan.go @@ -14,7 +14,7 @@ import ( ) type nodeActionTriggerPlanExpand struct { - *nodeAbstractActionTriggerExpand + *nodeAbstractActionTrigger resourceTargets []addrs.Targetable } @@ -27,14 +27,14 @@ var ( ) func (n *nodeActionTriggerPlanExpand) Name() string { - return fmt.Sprintf("%s (plan)", n.nodeAbstractActionTriggerExpand.Name()) + return fmt.Sprintf("%s (plan)", n.nodeAbstractActionTrigger.Name()) } func (n *nodeActionTriggerPlanExpand) DynamicExpand(ctx EvalContext) (*Graph, tfdiags.Diagnostics) { var g Graph var diags tfdiags.Diagnostics - if n.lifecycleActionTrigger == nil { + if n.triggerConfig == nil { panic("Only actions triggered by plan and apply are supported") } @@ -51,7 +51,7 @@ func (n *nodeActionTriggerPlanExpand) DynamicExpand(ctx EvalContext) (*Graph, tf for _, moduleAddr := range pem { actionAddr := moduleAddr.Action(n.Addr.Action) - resourceAddr := moduleAddr.Resource(n.lifecycleActionTrigger.resourceAddress.Resource) + resourceAddr := moduleAddr.Resource(n.triggerConfig.resourceAddress.Resource) // And add a node to the graph for this action. g.Add(&NodeActionTriggerPartialExpanded{ @@ -60,21 +60,21 @@ func (n *nodeActionTriggerPlanExpand) DynamicExpand(ctx EvalContext) (*Graph, tf resolvedProvider: n.resolvedProvider, lifecycleActionTrigger: &lifecycleActionTriggerPartialExpanded{ resourceAddress: resourceAddr, - events: n.lifecycleActionTrigger.events, - actionTriggerBlockIndex: n.lifecycleActionTrigger.actionTriggerBlockIndex, - actionListIndex: n.lifecycleActionTrigger.actionListIndex, - invokingSubject: n.lifecycleActionTrigger.invokingSubject, + events: n.triggerConfig.events, + actionTriggerBlockIndex: n.triggerConfig.actionTriggerBlockIndex, + actionListIndex: n.triggerConfig.actionListIndex, + invokingSubject: n.triggerConfig.invokingSubject, }, }) } } // First we expand the module - moduleInstances := expander.ExpandModule(n.lifecycleActionTrigger.resourceAddress.Module, false) + moduleInstances := expander.ExpandModule(n.triggerConfig.resourceAddress.Module, false) for _, module := range moduleInstances { - _, keys, _ := expander.ResourceInstanceKeys(n.lifecycleActionTrigger.resourceAddress.Absolute(module)) + _, keys, _ := expander.ResourceInstanceKeys(n.triggerConfig.resourceAddress.Absolute(module)) for _, key := range keys { - absResourceInstanceAddr := n.lifecycleActionTrigger.resourceAddress.Absolute(module).Instance(key) + absResourceInstanceAddr := n.triggerConfig.resourceAddress.Absolute(module).Instance(key) // If the triggering resource was targeted, make sure the instance // that triggered this was targeted specifically. @@ -106,7 +106,7 @@ func (n *nodeActionTriggerPlanExpand) DynamicExpand(ctx EvalContext) (*Graph, tf repData.EachValue = cty.DynamicVal } - ref, evalActionDiags := evaluateActionExpression(n.lifecycleActionTrigger.actionExpr, repData) + ref, evalActionDiags := evaluateActionExpression(n.triggerConfig.actionExpr, repData) diags = append(diags, evalActionDiags...) if diags.HasErrors() { continue @@ -127,11 +127,11 @@ func (n *nodeActionTriggerPlanExpand) DynamicExpand(ctx EvalContext) (*Graph, tf actionConfig: n.Config, lifecycleActionTrigger: &lifecycleActionTriggerInstance{ resourceAddress: absResourceInstanceAddr, - events: n.lifecycleActionTrigger.events, - actionTriggerBlockIndex: n.lifecycleActionTrigger.actionTriggerBlockIndex, - actionListIndex: n.lifecycleActionTrigger.actionListIndex, - invokingSubject: n.lifecycleActionTrigger.invokingSubject, - conditionExpr: n.lifecycleActionTrigger.conditionExpr, + events: n.triggerConfig.events, + actionTriggerBlockIndex: n.triggerConfig.actionTriggerBlockIndex, + actionListIndex: n.triggerConfig.actionListIndex, + invokingSubject: n.triggerConfig.invokingSubject, + conditionExpr: n.triggerConfig.conditionExpr, }, } diff --git a/internal/terraform/transform_action_diff.go b/internal/terraform/transform_action_diff.go index 8eccc791f2..0cc93ec995 100644 --- a/internal/terraform/transform_action_diff.go +++ b/internal/terraform/transform_action_diff.go @@ -22,8 +22,8 @@ func (t *ActionDiffTransformer) Transform(g *Graph) error { actionTriggerNodes := addrs.MakeMap[addrs.ConfigResource, []*nodeActionTriggerApplyExpand]() for _, vs := range g.Vertices() { if atn, ok := vs.(*nodeActionTriggerApplyExpand); ok { - configResource := actionTriggerNodes.Get(atn.lifecycleActionTrigger.resourceAddress) - actionTriggerNodes.Put(atn.lifecycleActionTrigger.resourceAddress, append(configResource, atn)) + configResource := actionTriggerNodes.Get(atn.triggerConfig.resourceAddress) + actionTriggerNodes.Put(atn.triggerConfig.resourceAddress, append(configResource, atn)) } } @@ -44,7 +44,7 @@ func (t *ActionDiffTransformer) Transform(g *Graph) error { beforeMatches := atn.relativeTiming == RelativeActionTimingBefore && isBefore afterMatches := atn.relativeTiming == RelativeActionTimingAfter && isAfter - if (beforeMatches || afterMatches) && atn.lifecycleActionTrigger.actionTriggerBlockIndex == lat.ActionTriggerBlockIndex && atn.lifecycleActionTrigger.actionListIndex == lat.ActionsListIndex { + if (beforeMatches || afterMatches) && atn.triggerConfig.actionTriggerBlockIndex == lat.ActionTriggerBlockIndex && atn.triggerConfig.actionListIndex == lat.ActionsListIndex { atn.actionInvocationInstances = append(atn.actionInvocationInstances, ai) } } diff --git a/internal/terraform/transform_action_trigger_config.go b/internal/terraform/transform_action_trigger_config.go index 670d92007c..04773ac6e5 100644 --- a/internal/terraform/transform_action_trigger_config.go +++ b/internal/terraform/transform_action_trigger_config.go @@ -127,10 +127,10 @@ func (t *ActionTriggerConfigTransformer) transformSingle(g *Graph, config *confi panic(fmt.Sprintf("Could not find node for %s", resourceAddr)) } - abstract := &nodeAbstractActionTriggerExpand{ + abstract := &nodeAbstractActionTrigger{ Addr: configAction, Config: actionConfig, - lifecycleActionTrigger: &lifecycleActionTrigger{ + triggerConfig: &actionTriggerConfig{ events: at.Events, resourceAddress: resourceAddr, actionExpr: action.Expr, diff --git a/internal/terraform/transform_provider.go b/internal/terraform/transform_provider.go index a877762be0..3c751b99a3 100644 --- a/internal/terraform/transform_provider.go +++ b/internal/terraform/transform_provider.go @@ -8,6 +8,7 @@ import ( "log" "github.com/hashicorp/hcl/v2" + "github.com/hashicorp/terraform/internal/addrs" "github.com/hashicorp/terraform/internal/configs" "github.com/hashicorp/terraform/internal/dag" @@ -103,13 +104,13 @@ func (t *ProviderTransformer) Transform(g *Graph) error { var diags tfdiags.Diagnostics // To start, we'll collect the _requested_ provider addresses for each - // node, which we'll then resolve (handling provider inheritence, etc) in + // node, which we'll then resolve (handling provider inheritance, etc) in // the next step. // Our "requested" map is from graph vertices to string representations of // provider config addresses (for deduping) to requests. type ProviderRequest struct { Addr addrs.AbsProviderConfig - Exact bool // If true, inheritence from parent modules is not attempted + Exact bool // If true, inheritance from parent modules is not attempted } requested := map[dag.Vertex]map[string]ProviderRequest{} needConfigured := map[string]addrs.AbsProviderConfig{} @@ -286,7 +287,7 @@ func (t *CloseProviderTransformer) Transform(g *Graph) error { // Now look for all provider consumers and connect them to the appropriate closers. for _, v := range g.Vertices() { - if actionNode, ok := v.(*nodeExpandActionDeclaration); ok { + if actionNode, ok := v.(*nodeExpandAction); ok { actionNodes.Put(actionNode.ActionAddr(), actionNode.ResolvedProvider) } pc, ok := v.(GraphNodeProviderConsumer) @@ -328,7 +329,7 @@ func (t *CloseProviderTransformer) Transform(g *Graph) error { // This transformer may create extra nodes that are not needed in practice, // due to overriding provider configurations in child modules. // PruneProviderTransformer can then remove these once ProviderTransformer -// has resolved all of the inheritence, etc. +// has resolved all of the inheritance, etc. type MissingProviderTransformer struct { // MissingProviderTransformer needs the config to rule out _implied_ default providers Config *configs.Config @@ -512,7 +513,7 @@ type ProviderConfigTransformer struct { // each provider node is stored here so that the proxy nodes can look up // their targets by name. providers map[string]GraphNodeProvider - // record providers that can be overriden with a proxy + // record providers that can be overridden with a proxy proxiable map[string]bool // Config is the root node of the configuration tree to add providers from. From 70e074b8aaae6e8ea082782f3a100c0106235853 Mon Sep 17 00:00:00 2001 From: Kristin Laemmert Date: Mon, 23 Feb 2026 15:12:12 -0500 Subject: [PATCH 2/2] chore (actions): rename LifecycleActionTrigger -> ResourceActionTrigger in plan and proto We'd previously removed all other references to "lifecycle" actions, which made this reference stand out. ResourceLifecycleActionTrigger is probably the most accurate name, but as this type just needs to be differentiated from InvokeActionTrigger I thought "resource" was enough (and I specifically wanted= to avoid lifecycle at all). I'm not super attached to the name, but I did think it would be clearer if we avoided Lifecycle as much as possible, since that's got some overlap with action subtypes. In this instance, we call it a LifecycleActionTrigger because it's come from the resource's `lifecycle` block. This doesn't directly relate to the concept of LifecycleActions - even if we expand the design to have multiple action types (for example generic and lifecycle actions), both those actions types would use this same Trigger struct. --- .../command/jsonplan/action_invocations.go | 2 +- internal/command/views/hook_json_test.go | 2 +- internal/command/views/json/change.go | 2 +- internal/command/views/json/hook.go | 8 +-- internal/command/views/operation_test.go | 6 +- internal/plans/action_invocation.go | 21 ++++--- internal/plans/changes_src.go | 8 +-- internal/plans/deferring/deferred.go | 2 +- internal/plans/planfile/tfplan.go | 22 +++---- internal/plans/planfile/tfplan_test.go | 8 +-- internal/plans/planproto/planfile.pb.go | 62 +++++++++---------- internal/plans/planproto/planfile.proto | 10 +-- .../terraform/context_apply_action_test.go | 2 +- .../terraform/context_plan_actions_test.go | 42 ++++++------- .../node_action_trigger_instance_apply.go | 2 +- .../node_action_trigger_instance_plan.go | 4 +- .../node_action_trigger_partialexp.go | 3 +- internal/terraform/transform_action_diff.go | 2 +- 18 files changed, 106 insertions(+), 102 deletions(-) diff --git a/internal/command/jsonplan/action_invocations.go b/internal/command/jsonplan/action_invocations.go index 203f8f9dc7..aa21965832 100644 --- a/internal/command/jsonplan/action_invocations.go +++ b/internal/command/jsonplan/action_invocations.go @@ -127,7 +127,7 @@ func MarshalActionInvocation(action *plans.ActionInvocationInstanceSrc, schemas } switch at := action.ActionTrigger.(type) { - case *plans.LifecycleActionTrigger: + case *plans.ResourceActionTrigger: ai.LifecycleActionTrigger = &LifecycleActionTrigger{ TriggeringResourceAddress: at.TriggeringResourceAddr.String(), ActionTriggerEvent: at.TriggerEvent().String(), diff --git a/internal/command/views/hook_json_test.go b/internal/command/views/hook_json_test.go index db8f865abe..17f0da3433 100644 --- a/internal/command/views/hook_json_test.go +++ b/internal/command/views/hook_json_test.go @@ -34,7 +34,7 @@ func testJSONHookResourceID(addr addrs.AbsResourceInstance) terraform.HookResour func testJSONLifecycleHook(actionAddr addrs.AbsActionInstance, triggeringResourceAddr addrs.AbsResourceInstance, actionTriggerIndex int, actionsListIndex int) terraform.HookActionIdentity { return terraform.HookActionIdentity{ Addr: actionAddr, - ActionTrigger: &plans.LifecycleActionTrigger{ + ActionTrigger: &plans.ResourceActionTrigger{ TriggeringResourceAddr: triggeringResourceAddr, ActionTriggerBlockIndex: actionTriggerIndex, ActionsListIndex: actionsListIndex, diff --git a/internal/command/views/json/change.go b/internal/command/views/json/change.go index d03e1f273a..e07e28a78e 100644 --- a/internal/command/views/json/change.go +++ b/internal/command/views/json/change.go @@ -65,7 +65,7 @@ func NewPlannedActionInvocation(aiSrc *plans.ActionInvocationInstanceSrc) *Actio } switch trigger := aiSrc.ActionTrigger.(type) { - case *plans.LifecycleActionTrigger: + case *plans.ResourceActionTrigger: ai.LifecycleTrigger = &ActionInvocationLifecycleTrigger{ TriggeringResource: newResourceAddr(trigger.TriggeringResourceAddr), TriggeringEvent: trigger.ActionTriggerEvent.String(), diff --git a/internal/command/views/json/hook.go b/internal/command/views/json/hook.go index 1be294aa84..1e6abad295 100644 --- a/internal/command/views/json/hook.go +++ b/internal/command/views/json/hook.go @@ -391,7 +391,7 @@ func NewActionStart(id terraform.HookActionIdentity) Hook { } switch trigger := id.ActionTrigger.(type) { - case *plans.LifecycleActionTrigger: + case *plans.ResourceActionTrigger: action.LifecycleTrigger = &lifecycleActionTrigger{ TriggeringResource: newResourceAddr(trigger.TriggeringResourceAddr), TriggerIndex: trigger.ActionTriggerBlockIndex, @@ -434,7 +434,7 @@ func NewActionProgress(id terraform.HookActionIdentity, message string) Hook { } switch trigger := id.ActionTrigger.(type) { - case *plans.LifecycleActionTrigger: + case *plans.ResourceActionTrigger: action.LifecycleTrigger = &lifecycleActionTrigger{ TriggeringResource: newResourceAddr(trigger.TriggeringResourceAddr), TriggerIndex: trigger.ActionTriggerBlockIndex, @@ -475,7 +475,7 @@ func NewActionComplete(id terraform.HookActionIdentity) Hook { } switch trigger := id.ActionTrigger.(type) { - case *plans.LifecycleActionTrigger: + case *plans.ResourceActionTrigger: action.LifecycleTrigger = &lifecycleActionTrigger{ TriggeringResource: newResourceAddr(trigger.TriggeringResourceAddr), TriggerIndex: trigger.ActionTriggerBlockIndex, @@ -518,7 +518,7 @@ func NewActionErrored(id terraform.HookActionIdentity, err error) Hook { } switch trigger := id.ActionTrigger.(type) { - case *plans.LifecycleActionTrigger: + case *plans.ResourceActionTrigger: action.LifecycleTrigger = &lifecycleActionTrigger{ TriggeringResource: newResourceAddr(trigger.TriggeringResourceAddr), TriggerIndex: trigger.ActionTriggerBlockIndex, diff --git a/internal/command/views/operation_test.go b/internal/command/views/operation_test.go index 105d7936a0..ae1b49a4a7 100644 --- a/internal/command/views/operation_test.go +++ b/internal/command/views/operation_test.go @@ -573,7 +573,7 @@ func TestOperationJSON_plan_with_actions(t *testing.T) { act1 := &plans.ActionInvocationInstanceSrc{ Addr: addrs.Action{Type: "test_action", Name: "hello"}.Instance(addrs.NoKey).Absolute(root), - ActionTrigger: &plans.LifecycleActionTrigger{ + ActionTrigger: &plans.ResourceActionTrigger{ TriggeringResourceAddr: boop, ActionTriggerEvent: configs.AfterCreate, ActionTriggerBlockIndex: 0, @@ -582,7 +582,7 @@ func TestOperationJSON_plan_with_actions(t *testing.T) { } act2 := &plans.ActionInvocationInstanceSrc{ Addr: addrs.Action{Type: "test_other_action", Name: "world"}.Instance(addrs.NoKey).Absolute(root), - ActionTrigger: &plans.LifecycleActionTrigger{ + ActionTrigger: &plans.ResourceActionTrigger{ TriggeringResourceAddr: boop, ActionTriggerEvent: configs.AfterCreate, ActionTriggerBlockIndex: 0, @@ -591,7 +591,7 @@ func TestOperationJSON_plan_with_actions(t *testing.T) { } act3 := &plans.ActionInvocationInstanceSrc{ Addr: addrs.Action{Type: "test_action", Name: "goodbye"}.Instance(addrs.IntKey(0)).Absolute(vpc), - ActionTrigger: &plans.LifecycleActionTrigger{ + ActionTrigger: &plans.ResourceActionTrigger{ TriggeringResourceAddr: beep, ActionTriggerEvent: configs.BeforeUpdate, ActionTriggerBlockIndex: 1, diff --git a/internal/plans/action_invocation.go b/internal/plans/action_invocation.go index ca97faea70..a842286898 100644 --- a/internal/plans/action_invocation.go +++ b/internal/plans/action_invocation.go @@ -46,11 +46,12 @@ type ActionTrigger interface { } var ( - _ ActionTrigger = (*LifecycleActionTrigger)(nil) + _ ActionTrigger = (*ResourceActionTrigger)(nil) _ ActionTrigger = (*InvokeActionTrigger)(nil) ) -type LifecycleActionTrigger struct { +// ResourceActionTrigger contains the action trigger configuration from the resource. +type ResourceActionTrigger struct { TriggeringResourceAddr addrs.AbsResourceInstance // Information about the trigger // The event that triggered this action invocation. @@ -61,18 +62,18 @@ type LifecycleActionTrigger struct { ActionsListIndex int } -func (t *LifecycleActionTrigger) TriggerEvent() configs.ActionTriggerEvent { +func (t *ResourceActionTrigger) TriggerEvent() configs.ActionTriggerEvent { return t.ActionTriggerEvent } -func (t *LifecycleActionTrigger) actionTriggerSigil() {} +func (t *ResourceActionTrigger) actionTriggerSigil() {} -func (t *LifecycleActionTrigger) String() string { +func (t *ResourceActionTrigger) String() string { return t.TriggeringResourceAddr.String() } -func (t *LifecycleActionTrigger) Equals(other ActionTrigger) bool { - o, ok := other.(*LifecycleActionTrigger) +func (t *ResourceActionTrigger) Equals(other ActionTrigger) bool { + o, ok := other.(*ResourceActionTrigger) if !ok { return false } @@ -83,8 +84,8 @@ func (t *LifecycleActionTrigger) Equals(other ActionTrigger) bool { t.ActionTriggerEvent == o.ActionTriggerEvent } -func (t *LifecycleActionTrigger) Less(other ActionTrigger) bool { - o, ok := other.(*LifecycleActionTrigger) +func (t *ResourceActionTrigger) Less(other ActionTrigger) bool { + o, ok := other.(*ResourceActionTrigger) if !ok { return false // We always want to show non-lifecycle actions first } @@ -98,6 +99,8 @@ func (t *LifecycleActionTrigger) Less(other ActionTrigger) bool { t.ActionTriggerEvent < o.ActionTriggerEvent) } +// InvokeActionTrigger contains the configuration for an action triggered +// (invoked) directly via CLI command. type InvokeActionTrigger struct{} func (t *InvokeActionTrigger) actionTriggerSigil() {} diff --git a/internal/plans/changes_src.go b/internal/plans/changes_src.go index 352fd103f8..b8479ccb6c 100644 --- a/internal/plans/changes_src.go +++ b/internal/plans/changes_src.go @@ -622,11 +622,11 @@ func (acs *ActionInvocationInstanceSrc) Less(other *ActionInvocationInstanceSrc) // of action invocations has already been filtered to invocations against the // same resource as the current invocation. func (acs *ActionInvocationInstanceSrc) FilterLaterActionInvocations(actionInvocations []*ActionInvocationInstanceSrc) []*ActionInvocationInstanceSrc { - needleLat := acs.ActionTrigger.(*LifecycleActionTrigger) + needleLat := acs.ActionTrigger.(*ResourceActionTrigger) var laterInvocations []*ActionInvocationInstanceSrc for _, invocation := range actionInvocations { - if lat, ok := invocation.ActionTrigger.(*LifecycleActionTrigger); ok { + if lat, ok := invocation.ActionTrigger.(*ResourceActionTrigger); ok { if sameTriggerEvent(lat, needleLat) && triggersLater(lat, needleLat) { laterInvocations = append(laterInvocations, invocation) } @@ -635,10 +635,10 @@ func (acs *ActionInvocationInstanceSrc) FilterLaterActionInvocations(actionInvoc return laterInvocations } -func sameTriggerEvent(one, two *LifecycleActionTrigger) bool { +func sameTriggerEvent(one, two *ResourceActionTrigger) bool { return one.ActionTriggerEvent == two.ActionTriggerEvent } -func triggersLater(one, two *LifecycleActionTrigger) bool { +func triggersLater(one, two *ResourceActionTrigger) bool { return one.ActionTriggerBlockIndex > two.ActionTriggerBlockIndex || (one.ActionTriggerBlockIndex == two.ActionTriggerBlockIndex && one.ActionsListIndex > two.ActionsListIndex) } diff --git a/internal/plans/deferring/deferred.go b/internal/plans/deferring/deferred.go index 5c5941d559..7217c182dc 100644 --- a/internal/plans/deferring/deferred.go +++ b/internal/plans/deferring/deferred.go @@ -749,7 +749,7 @@ func (d *Deferred) ShouldDeferActionInvocation(ai plans.ActionInvocationInstance var diags tfdiags.Diagnostics // We only want to defer actions that are lifecycle triggered - at, ok := ai.ActionTrigger.(*plans.LifecycleActionTrigger) + at, ok := ai.ActionTrigger.(*plans.ResourceActionTrigger) if !ok { return false, diags } diff --git a/internal/plans/planfile/tfplan.go b/internal/plans/planfile/tfplan.go index 95bdf2d250..5e430c59ce 100644 --- a/internal/plans/planfile/tfplan.go +++ b/internal/plans/planfile/tfplan.go @@ -1335,15 +1335,15 @@ func actionInvocationFromTfplan(rawAction *planproto.ActionInvocationInstance) ( ret.Addr = actionAddr switch at := rawAction.ActionTrigger.(type) { - case *planproto.ActionInvocationInstance_LifecycleActionTrigger: - triggeringResourceAddrs, diags := addrs.ParseAbsResourceInstanceStr(at.LifecycleActionTrigger.TriggeringResourceAddr) + case *planproto.ActionInvocationInstance_ResourceActionTrigger: + triggeringResourceAddrs, diags := addrs.ParseAbsResourceInstanceStr(at.ResourceActionTrigger.TriggeringResourceAddr) if diags.HasErrors() { return nil, fmt.Errorf("invalid resource instance address %q: %w", - at.LifecycleActionTrigger.TriggeringResourceAddr, diags.Err()) + at.ResourceActionTrigger.TriggeringResourceAddr, diags.Err()) } var ate configs.ActionTriggerEvent - switch at.LifecycleActionTrigger.TriggerEvent { + switch at.ResourceActionTrigger.TriggerEvent { case planproto.ActionTriggerEvent_BEFORE_CERATE: ate = configs.BeforeCreate case planproto.ActionTriggerEvent_AFTER_CREATE: @@ -1358,12 +1358,12 @@ func actionInvocationFromTfplan(rawAction *planproto.ActionInvocationInstance) ( ate = configs.AfterDestroy default: - return nil, fmt.Errorf("invalid action trigger event %s", at.LifecycleActionTrigger.TriggerEvent) + return nil, fmt.Errorf("invalid action trigger event %s", at.ResourceActionTrigger.TriggerEvent) } - ret.ActionTrigger = &plans.LifecycleActionTrigger{ + ret.ActionTrigger = &plans.ResourceActionTrigger{ TriggeringResourceAddr: triggeringResourceAddrs, - ActionTriggerBlockIndex: int(at.LifecycleActionTrigger.ActionTriggerBlockIndex), - ActionsListIndex: int(at.LifecycleActionTrigger.ActionsListIndex), + ActionTriggerBlockIndex: int(at.ResourceActionTrigger.ActionTriggerBlockIndex), + ActionsListIndex: int(at.ResourceActionTrigger.ActionsListIndex), ActionTriggerEvent: ate, } case *planproto.ActionInvocationInstance_InvokeActionTrigger: @@ -1406,7 +1406,7 @@ func actionInvocationToTfPlan(action *plans.ActionInvocationInstanceSrc) (*planp } switch at := action.ActionTrigger.(type) { - case *plans.LifecycleActionTrigger: + case *plans.ResourceActionTrigger: triggerEvent := planproto.ActionTriggerEvent_INVALID_EVENT switch at.ActionTriggerEvent { case configs.BeforeCreate: @@ -1422,8 +1422,8 @@ func actionInvocationToTfPlan(action *plans.ActionInvocationInstanceSrc) (*planp case configs.AfterDestroy: triggerEvent = planproto.ActionTriggerEvent_AFTER_DESTROY } - ret.ActionTrigger = &planproto.ActionInvocationInstance_LifecycleActionTrigger{ - LifecycleActionTrigger: &planproto.LifecycleActionTrigger{ + ret.ActionTrigger = &planproto.ActionInvocationInstance_ResourceActionTrigger{ + ResourceActionTrigger: &planproto.ResourceActionTrigger{ TriggerEvent: triggerEvent, TriggeringResourceAddr: at.TriggeringResourceAddr.String(), ActionTriggerBlockIndex: int64(at.ActionTriggerBlockIndex), diff --git a/internal/plans/planfile/tfplan_test.go b/internal/plans/planfile/tfplan_test.go index 5c339042bf..3270633e2b 100644 --- a/internal/plans/planfile/tfplan_test.go +++ b/internal/plans/planfile/tfplan_test.go @@ -322,7 +322,7 @@ func examplePlanForTest(t *testing.T) *plans.Plan { { Addr: addrs.Action{Type: "example", Name: "foo"}.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance), ProviderAddr: provider, - ActionTrigger: &plans.LifecycleActionTrigger{ + ActionTrigger: &plans.ResourceActionTrigger{ ActionTriggerEvent: configs.BeforeCreate, ActionTriggerBlockIndex: 2, ActionsListIndex: 0, @@ -336,7 +336,7 @@ func examplePlanForTest(t *testing.T) *plans.Plan { { Addr: addrs.Action{Type: "example", Name: "bar"}.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance), ProviderAddr: provider, - ActionTrigger: &plans.LifecycleActionTrigger{ + ActionTrigger: &plans.ResourceActionTrigger{ ActionTriggerEvent: configs.BeforeCreate, ActionTriggerBlockIndex: 2, ActionsListIndex: 1, @@ -353,7 +353,7 @@ func examplePlanForTest(t *testing.T) *plans.Plan { { Addr: addrs.Action{Type: "example", Name: "baz"}.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance), ProviderAddr: provider, - ActionTrigger: &plans.LifecycleActionTrigger{ + ActionTrigger: &plans.ResourceActionTrigger{ ActionTriggerEvent: configs.BeforeCreate, ActionTriggerBlockIndex: 2, ActionsListIndex: 1, @@ -458,7 +458,7 @@ func examplePlanForTest(t *testing.T) *plans.Plan { DeferredReason: providers.DeferredReasonDeferredPrereq, ActionInvocationInstanceSrc: &plans.ActionInvocationInstanceSrc{ Addr: addrs.Action{Type: "test_action", Name: "example"}.Absolute(addrs.RootModuleInstance).Instance(addrs.NoKey), - ActionTrigger: &plans.LifecycleActionTrigger{ + ActionTrigger: &plans.ResourceActionTrigger{ TriggeringResourceAddr: addrs.Resource{ Mode: addrs.ManagedResourceMode, Type: "test_thing", diff --git a/internal/plans/planproto/planfile.pb.go b/internal/plans/planproto/planfile.pb.go index e456840ada..ee1a4851d3 100644 --- a/internal/plans/planproto/planfile.pb.go +++ b/internal/plans/planproto/planfile.pb.go @@ -549,8 +549,8 @@ type Plan struct { // configuration. TargetAddrs []string `protobuf:"bytes,5,rep,name=target_addrs,json=targetAddrs,proto3" json:"target_addrs,omitempty"` // An unordered set of action addresses that must be invoked when applying. - // If no actions are specified then only lifecycle actions should be - // executed. + // If no actions are specified then only resource-triggered actions should + // be executed. ActionTargetAddrs []string `protobuf:"bytes,32,rep,name=action_target_addrs,json=actionTargetAddrs,proto3" json:"action_target_addrs,omitempty"` // An unordered set of force-replace addresses to include when applying. // This must match the set of addresses that was used when creating the @@ -1748,7 +1748,7 @@ type ActionInvocationInstance struct { SensitiveConfigPaths []*Path `protobuf:"bytes,5,rep,name=sensitive_config_paths,json=sensitiveConfigPaths,proto3" json:"sensitive_config_paths,omitempty"` // Types that are valid to be assigned to ActionTrigger: // - // *ActionInvocationInstance_LifecycleActionTrigger + // *ActionInvocationInstance_ResourceActionTrigger // *ActionInvocationInstance_InvokeActionTrigger ActionTrigger isActionInvocationInstance_ActionTrigger `protobuf_oneof:"action_trigger"` unknownFields protoimpl.UnknownFields @@ -1820,10 +1820,10 @@ func (x *ActionInvocationInstance) GetActionTrigger() isActionInvocationInstance return nil } -func (x *ActionInvocationInstance) GetLifecycleActionTrigger() *LifecycleActionTrigger { +func (x *ActionInvocationInstance) GetResourceActionTrigger() *ResourceActionTrigger { if x != nil { - if x, ok := x.ActionTrigger.(*ActionInvocationInstance_LifecycleActionTrigger); ok { - return x.LifecycleActionTrigger + if x, ok := x.ActionTrigger.(*ActionInvocationInstance_ResourceActionTrigger); ok { + return x.ResourceActionTrigger } } return nil @@ -1842,21 +1842,21 @@ type isActionInvocationInstance_ActionTrigger interface { isActionInvocationInstance_ActionTrigger() } -type ActionInvocationInstance_LifecycleActionTrigger struct { - LifecycleActionTrigger *LifecycleActionTrigger `protobuf:"bytes,6,opt,name=lifecycle_action_trigger,json=lifecycleActionTrigger,proto3,oneof"` +type ActionInvocationInstance_ResourceActionTrigger struct { + ResourceActionTrigger *ResourceActionTrigger `protobuf:"bytes,6,opt,name=resource_action_trigger,json=resourceActionTrigger,proto3,oneof"` } type ActionInvocationInstance_InvokeActionTrigger struct { InvokeActionTrigger *InvokeActionTrigger `protobuf:"bytes,7,opt,name=invoke_action_trigger,json=invokeActionTrigger,proto3,oneof"` } -func (*ActionInvocationInstance_LifecycleActionTrigger) isActionInvocationInstance_ActionTrigger() {} +func (*ActionInvocationInstance_ResourceActionTrigger) isActionInvocationInstance_ActionTrigger() {} func (*ActionInvocationInstance_InvokeActionTrigger) isActionInvocationInstance_ActionTrigger() {} -// LifecycleActionTrigger contains details on the conditions that led to the +// ResourceActionTrigger contains details on the conditions that led to the // triggering of an action. -type LifecycleActionTrigger struct { +type ResourceActionTrigger struct { state protoimpl.MessageState `protogen:"open.v1"` TriggeringResourceAddr string `protobuf:"bytes,1,opt,name=triggering_resource_addr,json=triggeringResourceAddr,proto3" json:"triggering_resource_addr,omitempty"` TriggerEvent ActionTriggerEvent `protobuf:"varint,2,opt,name=trigger_event,json=triggerEvent,proto3,enum=tfplan.ActionTriggerEvent" json:"trigger_event,omitempty"` @@ -1866,20 +1866,20 @@ type LifecycleActionTrigger struct { sizeCache protoimpl.SizeCache } -func (x *LifecycleActionTrigger) Reset() { - *x = LifecycleActionTrigger{} +func (x *ResourceActionTrigger) Reset() { + *x = ResourceActionTrigger{} mi := &file_planfile_proto_msgTypes[16] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } -func (x *LifecycleActionTrigger) String() string { +func (x *ResourceActionTrigger) String() string { return protoimpl.X.MessageStringOf(x) } -func (*LifecycleActionTrigger) ProtoMessage() {} +func (*ResourceActionTrigger) ProtoMessage() {} -func (x *LifecycleActionTrigger) ProtoReflect() protoreflect.Message { +func (x *ResourceActionTrigger) ProtoReflect() protoreflect.Message { mi := &file_planfile_proto_msgTypes[16] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -1891,33 +1891,33 @@ func (x *LifecycleActionTrigger) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use LifecycleActionTrigger.ProtoReflect.Descriptor instead. -func (*LifecycleActionTrigger) Descriptor() ([]byte, []int) { +// Deprecated: Use ResourceActionTrigger.ProtoReflect.Descriptor instead. +func (*ResourceActionTrigger) Descriptor() ([]byte, []int) { return file_planfile_proto_rawDescGZIP(), []int{16} } -func (x *LifecycleActionTrigger) GetTriggeringResourceAddr() string { +func (x *ResourceActionTrigger) GetTriggeringResourceAddr() string { if x != nil { return x.TriggeringResourceAddr } return "" } -func (x *LifecycleActionTrigger) GetTriggerEvent() ActionTriggerEvent { +func (x *ResourceActionTrigger) GetTriggerEvent() ActionTriggerEvent { if x != nil { return x.TriggerEvent } return ActionTriggerEvent_INVALID_EVENT } -func (x *LifecycleActionTrigger) GetActionTriggerBlockIndex() int64 { +func (x *ResourceActionTrigger) GetActionTriggerBlockIndex() int64 { if x != nil { return x.ActionTriggerBlockIndex } return 0 } -func (x *LifecycleActionTrigger) GetActionsListIndex() int64 { +func (x *ResourceActionTrigger) GetActionsListIndex() int64 { if x != nil { return x.ActionsListIndex } @@ -2349,16 +2349,16 @@ const file_planfile_proto_rawDesc = "" + "\aunknown\x18\x02 \x01(\bR\aunknown\x120\n" + "\bidentity\x18\x03 \x01(\v2\x14.tfplan.DynamicValueR\bidentity\":\n" + "\bDeferred\x12.\n" + - "\x06reason\x18\x01 \x01(\x0e2\x16.tfplan.DeferredReasonR\x06reason\"\x88\x03\n" + + "\x06reason\x18\x01 \x01(\x0e2\x16.tfplan.DeferredReasonR\x06reason\"\x85\x03\n" + "\x18ActionInvocationInstance\x12\x12\n" + "\x04addr\x18\x01 \x01(\tR\x04addr\x12\x1a\n" + "\bprovider\x18\x02 \x01(\tR\bprovider\x127\n" + "\fconfig_value\x18\x04 \x01(\v2\x14.tfplan.DynamicValueR\vconfigValue\x12B\n" + - "\x16sensitive_config_paths\x18\x05 \x03(\v2\f.tfplan.PathR\x14sensitiveConfigPaths\x12Z\n" + - "\x18lifecycle_action_trigger\x18\x06 \x01(\v2\x1e.tfplan.LifecycleActionTriggerH\x00R\x16lifecycleActionTrigger\x12Q\n" + + "\x16sensitive_config_paths\x18\x05 \x03(\v2\f.tfplan.PathR\x14sensitiveConfigPaths\x12W\n" + + "\x17resource_action_trigger\x18\x06 \x01(\v2\x1d.tfplan.ResourceActionTriggerH\x00R\x15resourceActionTrigger\x12Q\n" + "\x15invoke_action_trigger\x18\a \x01(\v2\x1b.tfplan.InvokeActionTriggerH\x00R\x13invokeActionTriggerB\x10\n" + - "\x0eaction_trigger\"\xfe\x01\n" + - "\x16LifecycleActionTrigger\x128\n" + + "\x0eaction_trigger\"\xfd\x01\n" + + "\x15ResourceActionTrigger\x128\n" + "\x18triggering_resource_addr\x18\x01 \x01(\tR\x16triggeringResourceAddr\x12?\n" + "\rtrigger_event\x18\x02 \x01(\x0e2\x1a.tfplan.ActionTriggerEventR\ftriggerEvent\x12;\n" + "\x1aaction_trigger_block_index\x18\x03 \x01(\x03R\x17actionTriggerBlockIndex\x12,\n" + @@ -2460,7 +2460,7 @@ var file_planfile_proto_goTypes = []any{ (*Importing)(nil), // 20: tfplan.Importing (*Deferred)(nil), // 21: tfplan.Deferred (*ActionInvocationInstance)(nil), // 22: tfplan.ActionInvocationInstance - (*LifecycleActionTrigger)(nil), // 23: tfplan.LifecycleActionTrigger + (*ResourceActionTrigger)(nil), // 23: tfplan.ResourceActionTrigger (*InvokeActionTrigger)(nil), // 24: tfplan.InvokeActionTrigger (*ResourceInstanceActionChange)(nil), // 25: tfplan.ResourceInstanceActionChange nil, // 26: tfplan.Plan.VariablesEntry @@ -2509,9 +2509,9 @@ var file_planfile_proto_depIdxs = []int32{ 3, // 37: tfplan.Deferred.reason:type_name -> tfplan.DeferredReason 18, // 38: tfplan.ActionInvocationInstance.config_value:type_name -> tfplan.DynamicValue 19, // 39: tfplan.ActionInvocationInstance.sensitive_config_paths:type_name -> tfplan.Path - 23, // 40: tfplan.ActionInvocationInstance.lifecycle_action_trigger:type_name -> tfplan.LifecycleActionTrigger + 23, // 40: tfplan.ActionInvocationInstance.resource_action_trigger:type_name -> tfplan.ResourceActionTrigger 24, // 41: tfplan.ActionInvocationInstance.invoke_action_trigger:type_name -> tfplan.InvokeActionTrigger - 4, // 42: tfplan.LifecycleActionTrigger.trigger_event:type_name -> tfplan.ActionTriggerEvent + 4, // 42: tfplan.ResourceActionTrigger.trigger_event:type_name -> tfplan.ActionTriggerEvent 11, // 43: tfplan.ResourceInstanceActionChange.change:type_name -> tfplan.Change 18, // 44: tfplan.Plan.VariablesEntry.value:type_name -> tfplan.DynamicValue 19, // 45: tfplan.Plan.resource_attr.attr:type_name -> tfplan.Path @@ -2530,7 +2530,7 @@ func file_planfile_proto_init() { return } file_planfile_proto_msgTypes[15].OneofWrappers = []any{ - (*ActionInvocationInstance_LifecycleActionTrigger)(nil), + (*ActionInvocationInstance_ResourceActionTrigger)(nil), (*ActionInvocationInstance_InvokeActionTrigger)(nil), } file_planfile_proto_msgTypes[22].OneofWrappers = []any{ diff --git a/internal/plans/planproto/planfile.proto b/internal/plans/planproto/planfile.proto index 9033aae600..5db1cf62ae 100644 --- a/internal/plans/planproto/planfile.proto +++ b/internal/plans/planproto/planfile.proto @@ -108,8 +108,8 @@ message Plan { repeated string target_addrs = 5; // An unordered set of action addresses that must be invoked when applying. - // If no actions are specified then only lifecycle actions should be - // executed. + // If no actions are specified then only resource-triggered actions should + // be executed. repeated string action_target_addrs = 32; // An unordered set of force-replace addresses to include when applying. @@ -478,14 +478,14 @@ message ActionInvocationInstance { repeated Path sensitive_config_paths = 5; oneof action_trigger { - LifecycleActionTrigger lifecycle_action_trigger = 6; + ResourceActionTrigger resource_action_trigger = 6; InvokeActionTrigger invoke_action_trigger = 7; } } -// LifecycleActionTrigger contains details on the conditions that led to the +// ResourceActionTrigger contains details on the conditions that led to the // triggering of an action. -message LifecycleActionTrigger { +message ResourceActionTrigger { string triggering_resource_addr = 1; ActionTriggerEvent trigger_event = 2; int64 action_trigger_block_index = 3; diff --git a/internal/terraform/context_apply_action_test.go b/internal/terraform/context_apply_action_test.go index a3ff6c4fc2..ce3ab311c7 100644 --- a/internal/terraform/context_apply_action_test.go +++ b/internal/terraform/context_apply_action_test.go @@ -102,7 +102,7 @@ resource "test_object" "a" { } evaluateHook := func(got HookActionIdentity, wantAddr string, wantEvent configs.ActionTriggerEvent) { - trigger := got.ActionTrigger.(*plans.LifecycleActionTrigger) + trigger := got.ActionTrigger.(*plans.ResourceActionTrigger) if trigger.ActionTriggerEvent != wantEvent { t.Errorf("wrong event, got %s, want %s", trigger.ActionTriggerEvent, wantEvent) diff --git a/internal/terraform/context_plan_actions_test.go b/internal/terraform/context_plan_actions_test.go index 12ff92e22f..18752837a4 100644 --- a/internal/terraform/context_plan_actions_test.go +++ b/internal/terraform/context_plan_actions_test.go @@ -368,7 +368,7 @@ resource "other_object" "a" { if action.Addr.String() != "action.ecosystem.hello" { t.Fatalf("expected action address to be 'action.ecosystem.hello', got '%s'", action.Addr) } - at, ok := action.ActionTrigger.(*plans.LifecycleActionTrigger) + at, ok := action.ActionTrigger.(*plans.ResourceActionTrigger) if !ok { t.Fatalf("expected action trigger to be a LifecycleActionTrigger, got %T", action.ActionTrigger) } @@ -415,7 +415,7 @@ resource "test_object" "a" { t.Fatalf("expected action address to be 'action.test_action.hello', got '%s'", action.Addr) } - at, ok := action.ActionTrigger.(*plans.LifecycleActionTrigger) + at, ok := action.ActionTrigger.(*plans.ResourceActionTrigger) if !ok { t.Fatalf("expected action trigger to be a LifecycleActionTrigger, got %T", action.ActionTrigger) } @@ -769,7 +769,7 @@ resource "test_object" "a" { triggeredEvents := []configs.ActionTriggerEvent{} for _, action := range p.Changes.ActionInvocations { - at, ok := action.ActionTrigger.(*plans.LifecycleActionTrigger) + at, ok := action.ActionTrigger.(*plans.ResourceActionTrigger) if !ok { t.Fatalf("expected action trigger to be a LifecycleActionTrigger, got %T", action.ActionTrigger) } @@ -834,7 +834,7 @@ resource "test_object" "a" { triggeredEvents := []configs.ActionTriggerEvent{} for _, action := range p.Changes.ActionInvocations { - at, ok := action.ActionTrigger.(*plans.LifecycleActionTrigger) + at, ok := action.ActionTrigger.(*plans.ResourceActionTrigger) if !ok { t.Fatalf("expected action trigger to be a LifecycleActionTrigger, got %T", action.ActionTrigger) } @@ -894,7 +894,7 @@ resource "test_object" "a" { } for _, ai := range p.Changes.ActionInvocations { - at, ok := ai.ActionTrigger.(*plans.LifecycleActionTrigger) + at, ok := ai.ActionTrigger.(*plans.ResourceActionTrigger) if !ok { t.Fatalf("expected action trigger to be a LifecycleActionTrigger, got %T", ai.ActionTrigger) } @@ -948,7 +948,7 @@ resource "test_object" "a" { } for _, ai := range p.Changes.ActionInvocations { - at, ok := ai.ActionTrigger.(*plans.LifecycleActionTrigger) + at, ok := ai.ActionTrigger.(*plans.ResourceActionTrigger) if !ok { t.Fatalf("expected action trigger to be a LifecycleActionTrigger, got %T", ai.ActionTrigger) } @@ -1066,9 +1066,9 @@ resource "test_object" "a" { t.Fatalf("expected action addresses to be 'action.test_action.hello' and 'action.test_action.hello', got %v", actionAddrs) } - actionTriggers := []plans.LifecycleActionTrigger{} + actionTriggers := []plans.ResourceActionTrigger{} for _, ai := range p.Changes.ActionInvocations { - at, ok := ai.ActionTrigger.(*plans.LifecycleActionTrigger) + at, ok := ai.ActionTrigger.(*plans.ResourceActionTrigger) if !ok { t.Fatalf("expected action trigger to be a LifecycleActionTrigger, got %T", ai.ActionTrigger) } @@ -1127,9 +1127,9 @@ resource "test_object" "a" { t.Fatalf("expected action addresses to be 'action.test_action.hello[0]' and 'action.test_action.hello[1]', got %v", actionAddrs) } - actionTriggers := []plans.LifecycleActionTrigger{} + actionTriggers := []plans.ResourceActionTrigger{} for _, ai := range p.Changes.ActionInvocations { - at, ok := ai.ActionTrigger.(*plans.LifecycleActionTrigger) + at, ok := ai.ActionTrigger.(*plans.ResourceActionTrigger) if !ok { t.Fatalf("expected action trigger to be a LifecycleActionTrigger, got %T", ai.ActionTrigger) } @@ -1642,7 +1642,7 @@ resource "other_object" "a" { t.Fatalf("expected action address to be 'module.mod.action.test_action.hello', got '%s'", action.Addr) } - at, ok := action.ActionTrigger.(*plans.LifecycleActionTrigger) + at, ok := action.ActionTrigger.(*plans.ResourceActionTrigger) if !ok { t.Fatalf("expected action trigger to be a LifecycleActionTrigger, got %T", action.ActionTrigger) } @@ -1696,11 +1696,11 @@ resource "other_object" "a" { // We know we are run within two child modules, so we can just sort by the triggering resource address slices.SortFunc(p.Changes.ActionInvocations, func(a, b *plans.ActionInvocationInstanceSrc) int { - at, ok := a.ActionTrigger.(*plans.LifecycleActionTrigger) + at, ok := a.ActionTrigger.(*plans.ResourceActionTrigger) if !ok { t.Fatalf("expected action trigger to be a LifecycleActionTrigger, got %T", a.ActionTrigger) } - bt, ok := b.ActionTrigger.(*plans.LifecycleActionTrigger) + bt, ok := b.ActionTrigger.(*plans.ResourceActionTrigger) if !ok { t.Fatalf("expected action trigger to be a LifecycleActionTrigger, got %T", b.ActionTrigger) } @@ -1716,7 +1716,7 @@ resource "other_object" "a" { t.Fatalf("expected action address to be 'module.mod[0].action.test_action.hello', got '%s'", action.Addr) } - at := action.ActionTrigger.(*plans.LifecycleActionTrigger) + at := action.ActionTrigger.(*plans.ResourceActionTrigger) if !at.TriggeringResourceAddr.Equal(mustResourceInstanceAddr("module.mod[0].other_object.a")) { t.Fatalf("expected action to have triggering resource address 'module.mod[0].other_object.a', but it is %s", at.TriggeringResourceAddr) @@ -1741,7 +1741,7 @@ resource "other_object" "a" { t.Fatalf("expected action address to be 'module.mod[1].action.test_action.hello', got '%s'", action2.Addr) } - a2t := action2.ActionTrigger.(*plans.LifecycleActionTrigger) + a2t := action2.ActionTrigger.(*plans.ResourceActionTrigger) if !a2t.TriggeringResourceAddr.Equal(mustResourceInstanceAddr("module.mod[1].other_object.a")) { t.Fatalf("expected action to have triggering resource address 'module.mod[1].other_object.a', but it is %s", a2t.TriggeringResourceAddr) @@ -1861,7 +1861,7 @@ resource "other_object" "a" { t.Fatalf("expected action address to be 'module.mod.action.test_action.hello', got '%s'", action.Addr) } - at, ok := action.ActionTrigger.(*plans.LifecycleActionTrigger) + at, ok := action.ActionTrigger.(*plans.ResourceActionTrigger) if !ok { t.Fatalf("expected action trigger to be a lifecycle action trigger, got %T", action.ActionTrigger) } @@ -1916,7 +1916,7 @@ resource "other_object" "a" { t.Fatalf("expected action address to be 'action.test_action.hello', got '%s'", action.Addr) } - at, ok := action.ActionTrigger.(*plans.LifecycleActionTrigger) + at, ok := action.ActionTrigger.(*plans.ResourceActionTrigger) if !ok { t.Fatalf("expected action trigger to be a LifecycleActionTrigger, got %T", action.ActionTrigger) } @@ -2173,8 +2173,8 @@ resource "test_object" "a" { t.Fatalf("expected deferred action to be deferred due to deferred prereq, but got %s", firstDeferredActionInvocation.DeferredReason) } - if firstDeferredActionInvocation.ActionInvocationInstanceSrc.ActionTrigger.(*plans.LifecycleActionTrigger).TriggeringResourceAddr.String() != "test_object.a" { - t.Fatalf("expected deferred action to be triggered by test_object.a, but got %s", firstDeferredActionInvocation.ActionInvocationInstanceSrc.ActionTrigger.(*plans.LifecycleActionTrigger).TriggeringResourceAddr.String()) + if firstDeferredActionInvocation.ActionInvocationInstanceSrc.ActionTrigger.(*plans.ResourceActionTrigger).TriggeringResourceAddr.String() != "test_object.a" { + t.Fatalf("expected deferred action to be triggered by test_object.a, but got %s", firstDeferredActionInvocation.ActionInvocationInstanceSrc.ActionTrigger.(*plans.ResourceActionTrigger).TriggeringResourceAddr.String()) } if firstDeferredActionInvocation.ActionInvocationInstanceSrc.Addr.String() != "action.test_action.hello" { @@ -2185,8 +2185,8 @@ resource "test_object" "a" { if secondDeferredActionInvocation.DeferredReason != providers.DeferredReasonDeferredPrereq { t.Fatalf("expected second deferred action to be deferred due to deferred prereq, but got %s", secondDeferredActionInvocation.DeferredReason) } - if secondDeferredActionInvocation.ActionInvocationInstanceSrc.ActionTrigger.(*plans.LifecycleActionTrigger).TriggeringResourceAddr.String() != "test_object.a" { - t.Fatalf("expected second deferred action to be triggered by test_object.a, but got %s", secondDeferredActionInvocation.ActionInvocationInstanceSrc.ActionTrigger.(*plans.LifecycleActionTrigger).TriggeringResourceAddr.String()) + if secondDeferredActionInvocation.ActionInvocationInstanceSrc.ActionTrigger.(*plans.ResourceActionTrigger).TriggeringResourceAddr.String() != "test_object.a" { + t.Fatalf("expected second deferred action to be triggered by test_object.a, but got %s", secondDeferredActionInvocation.ActionInvocationInstanceSrc.ActionTrigger.(*plans.ResourceActionTrigger).TriggeringResourceAddr.String()) } if secondDeferredActionInvocation.ActionInvocationInstanceSrc.Addr.String() != "action.test_action.hello" { diff --git a/internal/terraform/node_action_trigger_instance_apply.go b/internal/terraform/node_action_trigger_instance_apply.go index 5867d0e3b0..8c8be85155 100644 --- a/internal/terraform/node_action_trigger_instance_apply.go +++ b/internal/terraform/node_action_trigger_instance_apply.go @@ -42,7 +42,7 @@ func (n *nodeActionTriggerApplyInstance) Execute(ctx EvalContext, wo walkOperati if n.ConditionExpr != nil { // We know this must be a lifecycle action, otherwise we would have no condition - at := actionInvocation.ActionTrigger.(*plans.LifecycleActionTrigger) + at := actionInvocation.ActionTrigger.(*plans.ResourceActionTrigger) condition, conditionDiags := evaluateActionCondition(ctx, actionConditionContext{ // For applying the triggering event is sufficient, if the condition could not have // been evaluated due to in invalid mix of events we would have caught it durin planning. diff --git a/internal/terraform/node_action_trigger_instance_plan.go b/internal/terraform/node_action_trigger_instance_plan.go index c014f08cfa..acaf78f89d 100644 --- a/internal/terraform/node_action_trigger_instance_plan.go +++ b/internal/terraform/node_action_trigger_instance_plan.go @@ -46,8 +46,8 @@ func (at *lifecycleActionTriggerInstance) Name() string { return fmt.Sprintf("%s.lifecycle.action_trigger[%d].actions[%d]", at.resourceAddress.String(), at.actionTriggerBlockIndex, at.actionListIndex) } -func (at *lifecycleActionTriggerInstance) ActionTrigger(triggeringEvent configs.ActionTriggerEvent) *plans.LifecycleActionTrigger { - return &plans.LifecycleActionTrigger{ +func (at *lifecycleActionTriggerInstance) ActionTrigger(triggeringEvent configs.ActionTriggerEvent) *plans.ResourceActionTrigger { + return &plans.ResourceActionTrigger{ TriggeringResourceAddr: at.resourceAddress, ActionTriggerBlockIndex: at.actionTriggerBlockIndex, ActionsListIndex: at.actionListIndex, diff --git a/internal/terraform/node_action_trigger_partialexp.go b/internal/terraform/node_action_trigger_partialexp.go index 7b5af5f82b..77adb0cfeb 100644 --- a/internal/terraform/node_action_trigger_partialexp.go +++ b/internal/terraform/node_action_trigger_partialexp.go @@ -7,6 +7,7 @@ import ( "fmt" "github.com/hashicorp/hcl/v2" + "github.com/hashicorp/terraform/internal/addrs" "github.com/hashicorp/terraform/internal/configs" "github.com/hashicorp/terraform/internal/plans" @@ -118,7 +119,7 @@ func (n *NodeActionTriggerPartialExpanded) Execute(ctx EvalContext, op walkOpera ctx.Deferrals().ReportActionInvocationDeferred(plans.ActionInvocationInstance{ Addr: n.addr.UnknownActionInstance(), ProviderAddr: n.resolvedProvider, - ActionTrigger: &plans.LifecycleActionTrigger{ + ActionTrigger: &plans.ResourceActionTrigger{ TriggeringResourceAddr: n.lifecycleActionTrigger.resourceAddress.UnknownResourceInstance(), ActionTriggerEvent: triggeringEvent, ActionTriggerBlockIndex: n.lifecycleActionTrigger.actionTriggerBlockIndex, diff --git a/internal/terraform/transform_action_diff.go b/internal/terraform/transform_action_diff.go index 0cc93ec995..85abff7305 100644 --- a/internal/terraform/transform_action_diff.go +++ b/internal/terraform/transform_action_diff.go @@ -28,7 +28,7 @@ func (t *ActionDiffTransformer) Transform(g *Graph) error { } for _, ai := range t.Changes.ActionInvocations { - lat, ok := ai.ActionTrigger.(*plans.LifecycleActionTrigger) + lat, ok := ai.ActionTrigger.(*plans.ResourceActionTrigger) if !ok { continue }