|
|
|
|
@ -19,9 +19,7 @@ type ActionTriggerConfigTransformer struct {
|
|
|
|
|
|
|
|
|
|
queryPlanMode bool
|
|
|
|
|
|
|
|
|
|
ConcreteActionTriggerNodeFunc ConcreteActionTriggerNodeFunc
|
|
|
|
|
CreateNodesAsAfter bool
|
|
|
|
|
ConnectToResourceInstanceNodes bool // if false it connects to resource nodes instead of resource instance nodes
|
|
|
|
|
ConcreteActionTriggerNodeFunc ConcreteActionTriggerNodeFunc
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (t *ActionTriggerConfigTransformer) Transform(g *Graph) error {
|
|
|
|
|
@ -50,6 +48,10 @@ func (t *ActionTriggerConfigTransformer) transform(g *Graph, config *configs.Con
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (t *ActionTriggerConfigTransformer) transformSingle(g *Graph, config *configs.Config) error {
|
|
|
|
|
// During plan we only want to create all triggers to run after the resource
|
|
|
|
|
createNodesAsAfter := t.Operation == walkPlan
|
|
|
|
|
// During apply we want all after trigger to also connect to the resource instance nodes
|
|
|
|
|
connectToResourceInstanceNodes := t.Operation == walkApply
|
|
|
|
|
actionConfigs := addrs.MakeMap[addrs.ConfigAction, *configs.Action]()
|
|
|
|
|
for _, a := range config.Module.Actions {
|
|
|
|
|
actionConfigs.Put(a.Addr().InModule(config.Path), a)
|
|
|
|
|
@ -141,19 +143,18 @@ func (t *ActionTriggerConfigTransformer) transformSingle(g *Graph, config *confi
|
|
|
|
|
|
|
|
|
|
// If CreateNodesAsAfter is set we want all nodes to run after the resource
|
|
|
|
|
// If not we want expansion nodes only to exist if they are being used
|
|
|
|
|
if !t.CreateNodesAsAfter && containsBeforeEvent {
|
|
|
|
|
if !createNodesAsAfter && containsBeforeEvent {
|
|
|
|
|
nat := t.ConcreteActionTriggerNodeFunc(abstract, RelativeActionTimingBefore)
|
|
|
|
|
g.Add(nat)
|
|
|
|
|
|
|
|
|
|
// We want to run before the resource nodes
|
|
|
|
|
if t.ConnectToResourceInstanceNodes {
|
|
|
|
|
for _, node := range resourceNode {
|
|
|
|
|
g.Connect(dag.BasicEdge(node, nat))
|
|
|
|
|
}
|
|
|
|
|
if connectToResourceInstanceNodes {
|
|
|
|
|
for _, node := range resourceInstanceNodes.Get(resourceAddr) {
|
|
|
|
|
g.Connect(dag.BasicEdge(node, nat))
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
for _, node := range resourceNode {
|
|
|
|
|
g.Connect(dag.BasicEdge(node, nat))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We want to run after all prior nodes
|
|
|
|
|
@ -163,19 +164,18 @@ func (t *ActionTriggerConfigTransformer) transformSingle(g *Graph, config *confi
|
|
|
|
|
priorBeforeNodes = append(priorBeforeNodes, nat)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if t.CreateNodesAsAfter || containsAfterEvent {
|
|
|
|
|
if createNodesAsAfter || containsAfterEvent {
|
|
|
|
|
nat := t.ConcreteActionTriggerNodeFunc(abstract, RelativeActionTimingAfter)
|
|
|
|
|
g.Add(nat)
|
|
|
|
|
|
|
|
|
|
// We want to run after the resource nodes
|
|
|
|
|
if t.ConnectToResourceInstanceNodes {
|
|
|
|
|
for _, node := range resourceNode {
|
|
|
|
|
g.Connect(dag.BasicEdge(nat, node))
|
|
|
|
|
}
|
|
|
|
|
if connectToResourceInstanceNodes {
|
|
|
|
|
for _, node := range resourceInstanceNodes.Get(resourceAddr) {
|
|
|
|
|
g.Connect(dag.BasicEdge(nat, node))
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
for _, node := range resourceNode {
|
|
|
|
|
g.Connect(dag.BasicEdge(nat, node))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We want to run after all prior nodes
|
|
|
|
|
|