From d79e5a1477986c92a040ed8115c8d4e44a2bbe0e Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Tue, 4 Nov 2025 06:55:06 +0000 Subject: [PATCH] backport of commit 01af38e0dff8894071d058e0fc021a66c1ef8116 --- internal/terraform/context_plan_actions_test.go | 5 +++-- internal/terraform/transform_config.go | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/internal/terraform/context_plan_actions_test.go b/internal/terraform/context_plan_actions_test.go index e3f0c50cb1..3df836b8fb 100644 --- a/internal/terraform/context_plan_actions_test.go +++ b/internal/terraform/context_plan_actions_test.go @@ -4088,8 +4088,9 @@ resource "test_object" "a" { if !diags.HasErrors() { t.Fatal("expected errors, got success!") } - if diags.Err().Error() != "Configuration for triggered action does not exist: The configuration for the given action action.test_action.hello does not exist. All triggered actions must have an associated configuration." { - t.Fatal("wrong error!") + expectedErr := "action_trigger actions references non-existent action: The lifecycle action_trigger actions list contains a reference to the action \"action.test_action.hello\" that does not exist in the configuration of this module. This can likely be a typo." + if diags.Err().Error() != expectedErr { + t.Fatalf("wrong error!, got %q, expected %q", diags.Err().Error(), expectedErr) } } diff --git a/internal/terraform/transform_config.go b/internal/terraform/transform_config.go index 8198faad96..051d712b06 100644 --- a/internal/terraform/transform_config.go +++ b/internal/terraform/transform_config.go @@ -164,7 +164,7 @@ func (t *ConfigTransformer) transformSingle(g *Graph, config *configs.Config) er // Verify that any actions referenced in the resource's ActionTriggers exist in this module var diags tfdiags.Diagnostics if r.Managed != nil && r.Managed.ActionTriggers != nil { - for i, at := range r.Managed.ActionTriggers { + for _, at := range r.Managed.ActionTriggers { for _, action := range at.Actions { refs, parseRefDiags := langrefs.ReferencesInExpr(addrs.ParseRef, action.Expr) @@ -192,9 +192,10 @@ func (t *ConfigTransformer) transformSingle(g *Graph, config *configs.Config) er if !ok { diags = diags.Append(&hcl.Diagnostic{ Severity: hcl.DiagError, - Summary: "Configuration for triggered action does not exist", - Detail: fmt.Sprintf("The configuration for the given action %s does not exist. All triggered actions must have an associated configuration.", configAction.String()), - Subject: &r.Managed.ActionTriggers[i].DeclRange, + Summary: "action_trigger actions references non-existent action", + Detail: fmt.Sprintf("The lifecycle action_trigger actions list contains a reference to the action %q that does not exist in the configuration of this module. This can likely be a typo.", configAction.String()), + Subject: action.Expr.Range().Ptr(), + Context: r.DeclRange.Ptr(), }) } }