ensure actions dont break the graph in modules with no instances

This commit is contained in:
Daniel Schmidt 2026-01-23 10:24:23 +01:00
parent ece56bda45
commit 492d342aab
4 changed files with 108 additions and 3 deletions

View file

@ -0,0 +1,5 @@
kind: BUG FIXES
body: actions in modules without instances failed the plan graph
time: 2026-01-23T10:33:07.244665+01:00
custom:
Issue: "38089"

View file

@ -783,6 +783,32 @@ resource "test_object" "a" {
}},
},
"not triggered with no module instances": {
module: map[string]string{
"main.tf": `
module "mod" {
count = 0
source = "./mod"
}
// an empty plan is not applyable so we have this extra resource here
resource "test_object" "a" {}
`,
"mod/mod.tf": `
action "action_example" "hello" {}
resource "test_object" "a" {
lifecycle {
action_trigger {
events = [before_create]
actions = [action.action_example.hello]
}
}
}
`,
},
expectInvokeActionCalled: false,
},
"provider is within module": {
module: map[string]string{
"main.tf": `

View file

@ -1749,6 +1749,82 @@ resource "other_object" "a" {
},
},
"not triggered if module is count=0": {
module: map[string]string{
"main.tf": `
module "mod" {
count = 0
source = "./mod"
}
`,
"mod/mod.tf": `
action "test_action" "hello" {}
resource "other_object" "a" {
lifecycle {
action_trigger {
events = [before_create]
actions = [action.test_action.hello]
}
}
}
`,
},
expectPlanActionCalled: false,
},
"not triggered if for_each is empty": {
module: map[string]string{
"main.tf": `
module "mod" {
for_each = toset([])
source = "./mod"
}
`,
"mod/mod.tf": `
action "test_action" "hello" {}
resource "other_object" "a" {
lifecycle {
action_trigger {
events = [before_create]
actions = [action.test_action.hello]
}
}
}
`,
},
expectPlanActionCalled: false,
},
"action declaration in module if module is count=0": {
module: map[string]string{
"main.tf": `
module "mod" {
count = 0
source = "./mod"
}
`,
"mod/mod.tf": `
action "test_action" "hello" {}
`,
},
expectPlanActionCalled: false,
},
"action declaration in module if for_each is empty": {
module: map[string]string{
"main.tf": `
module "mod" {
for_each = toset([])
source = "./mod"
}
`,
"mod/mod.tf": `
action "test_action" "hello" {}
`,
},
expectPlanActionCalled: false,
},
"provider is within module": {
module: map[string]string{
"main.tf": `

View file

@ -55,7 +55,6 @@ func (n *nodeExpandActionDeclaration) DynamicExpand(ctx EvalContext) (*Graph, tf
resolvedProvider: n.ResolvedProvider,
})
}
addRootNodeToGraph(&g)
}
for _, module := range moduleInstances {
@ -94,9 +93,8 @@ func (n *nodeExpandActionDeclaration) DynamicExpand(ctx EvalContext) (*Graph, tf
g.Add(&node)
}
addRootNodeToGraph(&g)
}
addRootNodeToGraph(&g)
return &g, diags
}