44package terraform
55
66import (
7- "log"
8-
97 "github.com/hashicorp/terraform/internal/addrs"
108 "github.com/hashicorp/terraform/internal/tfdiags"
119)
@@ -19,7 +17,6 @@ type nodeExpandApplyableResource struct {
1917}
2018
2119var (
22- _ GraphNodeDynamicExpandable = (* nodeExpandApplyableResource )(nil )
2320 _ GraphNodeReferenceable = (* nodeExpandApplyableResource )(nil )
2421 _ GraphNodeReferencer = (* nodeExpandApplyableResource )(nil )
2522 _ GraphNodeConfigResource = (* nodeExpandApplyableResource )(nil )
@@ -49,56 +46,14 @@ func (n *nodeExpandApplyableResource) Name() string {
4946 return n .NodeAbstractResource .Name () + " (expand)"
5047}
5148
52- func (n * nodeExpandApplyableResource ) DynamicExpand (ctx EvalContext ) (* Graph , error ) {
53- var g Graph
54-
49+ func (n * nodeExpandApplyableResource ) Execute (ctx EvalContext , op walkOperation ) tfdiags.Diagnostics {
50+ var diags tfdiags.Diagnostics
5551 expander := ctx .InstanceExpander ()
5652 moduleInstances := expander .ExpandModule (n .Addr .Module )
5753 for _ , module := range moduleInstances {
58- g .Add (& NodeApplyableResource {
59- NodeAbstractResource : n .NodeAbstractResource ,
60- Addr : n .Addr .Resource .Absolute (module ),
61- })
62- }
63- addRootNodeToGraph (& g )
64-
65- return & g , nil
66- }
67-
68- // NodeApplyableResource represents a resource that is "applyable":
69- // it may need to have its record in the state adjusted to match configuration.
70- //
71- // Unlike in the plan walk, this resource node does not DynamicExpand. Instead,
72- // it should be inserted into the same graph as any instances of the nodes
73- // with dependency edges ensuring that the resource is evaluated before any
74- // of its instances, which will turn ensure that the whole-resource record
75- // in the state is suitably prepared to receive any updates to instances.
76- type NodeApplyableResource struct {
77- * NodeAbstractResource
78-
79- Addr addrs.AbsResource
80- }
81-
82- var (
83- _ GraphNodeModuleInstance = (* NodeApplyableResource )(nil )
84- _ GraphNodeConfigResource = (* NodeApplyableResource )(nil )
85- _ GraphNodeExecutable = (* NodeApplyableResource )(nil )
86- _ GraphNodeProviderConsumer = (* NodeApplyableResource )(nil )
87- _ GraphNodeAttachResourceConfig = (* NodeApplyableResource )(nil )
88- _ GraphNodeReferencer = (* NodeApplyableResource )(nil )
89- )
90-
91- func (n * NodeApplyableResource ) Path () addrs.ModuleInstance {
92- return n .Addr .Module
93- }
94-
95- // GraphNodeExecutable
96- func (n * NodeApplyableResource ) Execute (ctx EvalContext , op walkOperation ) tfdiags.Diagnostics {
97- if n .Config == nil {
98- // Nothing to do, then.
99- log .Printf ("[TRACE] NodeApplyableResource: no configuration present for %s" , n .Name ())
100- return nil
54+ ctx = ctx .WithPath (module )
55+ diags = diags .Append (n .writeResourceState (ctx , n .Addr .Resource .Absolute (module )))
10156 }
10257
103- return n . writeResourceState ( ctx , n . Addr )
58+ return diags
10459}
0 commit comments