diff --git a/.changes/v1.15/BUG FIXES-20260427-092612.yaml b/.changes/v1.15/BUG FIXES-20260427-092612.yaml new file mode 100644 index 0000000000..644c047ec0 --- /dev/null +++ b/.changes/v1.15/BUG FIXES-20260427-092612.yaml @@ -0,0 +1,5 @@ +kind: BUG FIXES +body: Fixed crash when configuration has an invalid `action_trigger` nested block in `data` or `ephemeral` lifecycle blocks +time: 2026-04-27T09:26:12.662049-04:00 +custom: + Issue: "38402" diff --git a/internal/configs/resource.go b/internal/configs/resource.go index 8f4276a61b..4d7569a115 100644 --- a/internal/configs/resource.go +++ b/internal/configs/resource.go @@ -509,6 +509,13 @@ func decodeEphemeralBlock(block *hcl.Block, override bool) (*Resource, hcl.Diagn case "postcondition": r.Postconditions = append(r.Postconditions, cr) } + case "action_trigger": + diags = append(diags, &hcl.Diagnostic{ + Severity: hcl.DiagError, + Summary: "Invalid ephemeral resource lifecycle nested block", + Detail: fmt.Sprintf("The lifecycle nested block %q is defined only for managed resources (\"resource\" blocks), and is not valid for ephemeral resources.", block.Type), + Subject: block.TypeRange.Ptr(), + }) default: // The cases above should be exhaustive for all block types // defined in the lifecycle schema, so this shouldn't happen. @@ -685,6 +692,13 @@ func decodeDataBlock(block *hcl.Block, override, nested bool) (*Resource, hcl.Di case "postcondition": r.Postconditions = append(r.Postconditions, cr) } + case "action_trigger": + diags = append(diags, &hcl.Diagnostic{ + Severity: hcl.DiagError, + Summary: "Invalid data resource lifecycle nested block", + Detail: fmt.Sprintf("The lifecycle nested block %q is defined only for managed resources (\"resource\" blocks), and is not valid for data resources.", block.Type), + Subject: block.TypeRange.Ptr(), + }) default: // The cases above should be exhaustive for all block types // defined in the lifecycle schema, so this shouldn't happen. diff --git a/internal/configs/testdata/invalid-files/data-invalid-action-trigger.tf b/internal/configs/testdata/invalid-files/data-invalid-action-trigger.tf new file mode 100644 index 0000000000..f4a623f674 --- /dev/null +++ b/internal/configs/testdata/invalid-files/data-invalid-action-trigger.tf @@ -0,0 +1,10 @@ +action "test_action" "test" {} + +data "test_data" "test" { + lifecycle { + action_trigger { + actions = [action.test_action.test] + events = [after_create, after_update] + } + } +} diff --git a/internal/configs/testdata/invalid-files/ephemeral-invalid-action_trigger.tf b/internal/configs/testdata/invalid-files/ephemeral-invalid-action_trigger.tf new file mode 100644 index 0000000000..0df5384978 --- /dev/null +++ b/internal/configs/testdata/invalid-files/ephemeral-invalid-action_trigger.tf @@ -0,0 +1,10 @@ +action "test_action" "test" {} + +ephemeral "test_ephemeral" "test" { + lifecycle { + action_trigger { + actions = [action.test_action.test] + events = [after_create, after_update] + } + } +}