diff --git a/.changes/v1.15/ENHANCEMENTS-20251123-224500.yaml b/.changes/v1.15/ENHANCEMENTS-20251123-224500.yaml new file mode 100644 index 000000000000..68498dd5ab1b --- /dev/null +++ b/.changes/v1.15/ENHANCEMENTS-20251123-224500.yaml @@ -0,0 +1,3 @@ +kind: ENHANCEMENTS +body: 'core: Improved error message when an action trigger references an action expanded with count or for_each without specifying an instance' +time: 2025-11-23T22:45:00.000000+00:00 diff --git a/internal/terraform/context_plan_actions_test.go b/internal/terraform/context_plan_actions_test.go index 014a08489e1e..69befce568cf 100644 --- a/internal/terraform/context_plan_actions_test.go +++ b/internal/terraform/context_plan_actions_test.go @@ -967,7 +967,7 @@ resource "test_object" "a" { return diags.Append(&hcl.Diagnostic{ Severity: hcl.DiagError, Summary: "Reference to non-existent action instance", - Detail: "Action instance was not found in the current context.", + Detail: "The referenced action could not be found. If the action uses 'count' or 'for_each', ensure you reference a specific instance, such as action.example[0] or action.example[\"key\"].", Subject: &hcl.Range{ Filename: filepath.Join(m.Module.SourceDir, "main.tf"), Start: hcl.Pos{Line: 13, Column: 18, Byte: 224}, @@ -1002,7 +1002,7 @@ resource "test_object" "a" { return diags.Append(&hcl.Diagnostic{ Severity: hcl.DiagError, Summary: "Reference to non-existent action instance", - Detail: "Action instance was not found in the current context.", + Detail: "The referenced action could not be found. If the action uses 'count' or 'for_each', ensure you reference a specific instance, such as action.example[0] or action.example[\"key\"].", Subject: &hcl.Range{ Filename: filepath.Join(m.Module.SourceDir, "main.tf"), Start: hcl.Pos{Line: 13, Column: 18, Byte: 208}, diff --git a/internal/terraform/node_action_trigger_instance_plan.go b/internal/terraform/node_action_trigger_instance_plan.go index a32b71f04f67..38982967a20f 100644 --- a/internal/terraform/node_action_trigger_instance_plan.go +++ b/internal/terraform/node_action_trigger_instance_plan.go @@ -107,7 +107,7 @@ func (n *nodeActionTriggerPlanInstance) Execute(ctx EvalContext, operation walkO diags = diags.Append(&hcl.Diagnostic{ Severity: hcl.DiagError, Summary: "Reference to non-existent action instance", - Detail: "Action instance was not found in the current context.", + Detail: "The referenced action could not be found. If the action uses 'count' or 'for_each', ensure you reference a specific instance, such as action.example[0] or action.example[\"key\"].", Subject: n.lifecycleActionTrigger.invokingSubject, }) return diags