Skip to content

Commit 007228f

Browse files
add extra documentation
1 parent 6fd0eb8 commit 007228f

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

internal/terraform/node_action_trigger_plan.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,12 @@ func (n *nodeActionTriggerPlanExpand) DynamicExpand(ctx EvalContext) (*Graph, tf
101101
for _, key := range keys {
102102
absResourceInstanceAddr := n.lifecycleActionTrigger.resourceAddress.Absolute(module).Instance(key)
103103

104+
// If the triggering resource was targeted, make sure the instance
105+
// that triggered this was targeted specifically.
106+
// This is necessary since the expansion of a resource instance (and of an action trigger)
107+
// happens during the graph walk / execution, therefore the target transformer can not
108+
// filter out individual instances, this needs to happen during the graph walk / execution.
104109
if n.resourceTargets != nil {
105-
// If the triggering resource was targeted, make sure the instance
106-
// that triggered this was targeted specifically.
107110
matched := false
108111
for _, resourceTarget := range n.resourceTargets {
109112
if resourceTarget.TargetContains(absResourceInstanceAddr) {

internal/terraform/transform_targets.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (t *TargetsTransformer) selectTargetedNodes(g *Graph, addrs []addrs.Targeta
6666
// We need to add everything this node depends on or that is closely associated with
6767
// this node. In case of resource nodes, action triggers are considered closely related
6868
// since they belong to the resource.
69-
t.addDependencies(g, v, targetedNodes, addrs)
69+
t.addVertexDependenciesToTargetedNodes(g, v, targetedNodes, addrs)
7070

7171
// We inform nodes that ask about the list of targets - helps for nodes
7272
// that need to dynamically expand. Note that this only occurs for nodes
@@ -138,26 +138,27 @@ func (t *TargetsTransformer) selectTargetedNodes(g *Graph, addrs []addrs.Targeta
138138
return targetedNodes
139139
}
140140

141-
// addDependencies adds dependencies of the targeted vertex. This includes all ancestors in the
142-
// graph. It also includes all action trigger nodes in the graph. Actions are planned after the
141+
// addVertexDependenciesToTargetedNodes adds dependencies of the targeted vertex to the
142+
// targetedNodes set. This includes all ancestors in the graph.
143+
// It also includes all action trigger nodes in the graph. Actions are planned after the
143144
// triggering node has planned so that we can ensure the actions are only planned if the triggering
144145
// resource has an action (Create / Update) corresponding to one of the events in the action trigger
145146
// blocks event list.
146-
func (t *TargetsTransformer) addDependencies(g *Graph, v dag.Vertex, targetedNodes dag.Set, addrs []addrs.Targetable) {
147+
func (t *TargetsTransformer) addVertexDependenciesToTargetedNodes(g *Graph, v dag.Vertex, targetedNodes dag.Set, addrs []addrs.Targetable) {
147148
if targetedNodes.Include(v) {
148149
return
149150
}
150151
targetedNodes.Add(v)
151152

152153
for _, d := range g.Ancestors(v) {
153-
t.addDependencies(g, d, targetedNodes, addrs)
154+
t.addVertexDependenciesToTargetedNodes(g, d, targetedNodes, addrs)
154155
}
155156

156157
if _, ok := v.(*nodeExpandPlannableResource); ok {
157158
// We want to also add the action triggers related to this resource
158159
for _, d := range g.Children(v) {
159160
if _, ok := d.(*nodeActionTriggerPlanExpand); ok {
160-
t.addDependencies(g, d, targetedNodes, addrs)
161+
t.addVertexDependenciesToTargetedNodes(g, d, targetedNodes, addrs)
161162
}
162163
}
163164
}
@@ -167,7 +168,7 @@ func (t *TargetsTransformer) addDependencies(g *Graph, v dag.Vertex, targetedNod
167168
if _, ok := v.(*NodeApplyableResourceInstance); ok {
168169
for _, f := range g.Children(v) {
169170
if _, ok := f.(*nodeActionTriggerApply); ok {
170-
t.addDependencies(g, f, targetedNodes, addrs)
171+
t.addVertexDependenciesToTargetedNodes(g, f, targetedNodes, addrs)
171172
}
172173
}
173174
}

0 commit comments

Comments
 (0)