Backport of Fix panic for invalid `action_trigger` nested blocks in `data` and `ephemeral` into v1.15 (#38452)

* backport of commit e65b690f80

* backport of commit f69f06a1ff

---------

Co-authored-by: Austin Valle <austinvalle@gmail.com>
pull/38477/head
github-actions[bot] 4 weeks ago committed by GitHub
parent 20d2eab8e1
commit 2c0fc76072
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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"

@ -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.

@ -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]
}
}
}

@ -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]
}
}
}
Loading…
Cancel
Save