From 2c0fc76072d608cbe1a57f0b79cae02541a6f6bc Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 29 Apr 2026 15:09:37 -0400 Subject: [PATCH] Backport of Fix panic for invalid `action_trigger` nested blocks in `data` and `ephemeral` into v1.15 (#38452) * backport of commit e65b690f805e69d24be3cded11f493b32c4f886a * backport of commit f69f06a1ffe6409f4a1e259b547dac04908e56fe --------- Co-authored-by: Austin Valle --- .changes/v1.15/BUG FIXES-20260427-092612.yaml | 5 +++++ internal/configs/resource.go | 14 ++++++++++++++ .../invalid-files/data-invalid-action-trigger.tf | 10 ++++++++++ .../ephemeral-invalid-action_trigger.tf | 10 ++++++++++ 4 files changed, 39 insertions(+) create mode 100644 .changes/v1.15/BUG FIXES-20260427-092612.yaml create mode 100644 internal/configs/testdata/invalid-files/data-invalid-action-trigger.tf create mode 100644 internal/configs/testdata/invalid-files/ephemeral-invalid-action_trigger.tf 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] + } + } +}