Skip to content

Commit 974f107

Browse files
add a way for action apply and resource instance nodes to announce the providers they need
1 parent 47832df commit 974f107

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

internal/terraform/node_action_apply.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ type nodeActionApply struct {
2121
}
2222

2323
var (
24-
_ GraphNodeExecutable = (*nodeActionApply)(nil)
25-
_ GraphNodeReferencer = (*nodeActionApply)(nil)
26-
_ dag.GraphNodeDotter = (*nodeActionApply)(nil)
24+
_ GraphNodeExecutable = (*nodeActionApply)(nil)
25+
_ GraphNodeReferencer = (*nodeActionApply)(nil)
26+
_ dag.GraphNodeDotter = (*nodeActionApply)(nil)
27+
_ GraphNodeActionProviders = (*nodeActionApply)(nil)
2728
)
2829

2930
func (n *nodeActionApply) Name() string {
@@ -154,3 +155,11 @@ func (n *nodeActionApply) References() []*addrs.Reference {
154155

155156
return refs
156157
}
158+
159+
func (n *nodeActionApply) ActionProviders() []addrs.AbsProviderConfig {
160+
ret := []addrs.AbsProviderConfig{}
161+
for _, invocation := range n.ActionInvocations {
162+
ret = append(ret, invocation.ProviderAddr)
163+
}
164+
return ret
165+
}

internal/terraform/node_resource_apply_instance.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ var (
4949
_ GraphNodeExecutable = (*NodeApplyableResourceInstance)(nil)
5050
_ GraphNodeAttachDependencies = (*NodeApplyableResourceInstance)(nil)
5151
_ GraphNodeAttachBeforeActions = (*NodeApplyableResourceInstance)(nil)
52+
_ GraphNodeActionProviders = (*NodeApplyableResourceInstance)(nil)
5253
)
5354

5455
// GraphNodeCreator
@@ -479,6 +480,14 @@ func (n *NodeApplyableResourceInstance) AttachBeforeActions(ais []*plans.ActionI
479480
n.beforeActionInvocations = ais
480481
}
481482

483+
func (n *NodeApplyableResourceInstance) ActionProviders() []addrs.AbsProviderConfig {
484+
ret := []addrs.AbsProviderConfig{}
485+
for _, ai := range n.beforeActionInvocations {
486+
ret = append(ret, ai.ProviderAddr)
487+
}
488+
return ret
489+
}
490+
482491
// maybeTainted takes the resource addr, new value, planned change, and possible
483492
// error from an apply operation and return a new instance object marked as
484493
// tainted if it appears that a create operation has failed.

internal/terraform/transform_provider.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ type GraphNodeProviderConsumer interface {
8787
SetProvider(addrs.AbsProviderConfig)
8888
}
8989

90+
type GraphNodeActionProviders interface {
91+
ActionProviders() []addrs.AbsProviderConfig
92+
}
93+
9094
// ProviderTransformer is a GraphTransformer that maps resources to providers
9195
// within the graph. This will error if there are any resources that don't map
9296
// to proper resources.
@@ -306,6 +310,22 @@ func (t *CloseProviderTransformer) Transform(g *Graph) error {
306310
g.Connect(dag.BasicEdge(closer, v))
307311
}
308312

313+
// Now look at all action provider consumers and connect them to the appropriate closers.
314+
for _, v := range g.Vertices() {
315+
apc, ok := v.(GraphNodeActionProviders)
316+
if !ok {
317+
continue
318+
}
319+
320+
for _, provider := range apc.ActionProviders() {
321+
closer, ok := cpm[provider.String()]
322+
if !ok {
323+
return fmt.Errorf("no graphNodeCloseProvider for %s", provider)
324+
}
325+
g.Connect(dag.BasicEdge(closer, v))
326+
}
327+
}
328+
309329
return err
310330
}
311331

0 commit comments

Comments
 (0)