Skip to content

Commit 085c762

Browse files
actions can not be used in depends_on
Fixed #37780
1 parent cbda324 commit 085c762

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

internal/terraform/context_plan_actions_test.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,75 @@ output "my_output2" {
319319
},
320320
},
321321

322+
"actions can't be used in depends_on": {
323+
module: map[string]string{
324+
"main.tf": `
325+
action "test_action" "my_action" {
326+
config {
327+
attr = "value"
328+
}
329+
}
330+
resource "test_object" "a" {
331+
depends_on = [action.test_action.my_action]
332+
lifecycle {
333+
action_trigger {
334+
events = [before_create]
335+
actions = [action.test_action.my_action]
336+
}
337+
}
338+
}
339+
`,
340+
},
341+
expectValidateDiagnostics: func(m *configs.Config) tfdiags.Diagnostics {
342+
return tfdiags.Diagnostics{}.Append(
343+
&hcl.Diagnostic{
344+
Severity: hcl.DiagError,
345+
Summary: "Invalid depends_on reference",
346+
Detail: "Actions can not be referenced in depends_on. Use depends_on on the resource that triggers the action instead.",
347+
Subject: &hcl.Range{
348+
Filename: filepath.Join(m.Module.SourceDir, "main.tf"),
349+
Start: hcl.Pos{Line: 8, Column: 17, Byte: 117},
350+
End: hcl.Pos{Line: 8, Column: 45, Byte: 145},
351+
},
352+
})
353+
},
354+
},
355+
356+
"action instances can't be used in depends_on": {
357+
module: map[string]string{
358+
"main.tf": `
359+
action "test_action" "my_action" {
360+
count = 3
361+
config {
362+
attr = "value"
363+
}
364+
}
365+
resource "test_object" "a" {
366+
depends_on = [action.test_action.my_action[1]]
367+
lifecycle {
368+
action_trigger {
369+
events = [before_create]
370+
actions = [action.test_action.my_action[1]]
371+
}
372+
}
373+
}
374+
`,
375+
},
376+
expectValidateDiagnostics: func(m *configs.Config) tfdiags.Diagnostics {
377+
return tfdiags.Diagnostics{}.Append(
378+
&hcl.Diagnostic{
379+
Severity: hcl.DiagError,
380+
Summary: "Invalid depends_on reference",
381+
Detail: "Actions can not be referenced in depends_on. Use depends_on on the resource that triggers the action instead.",
382+
Subject: &hcl.Range{
383+
Filename: filepath.Join(m.Module.SourceDir, "main.tf"),
384+
Start: hcl.Pos{Line: 9, Column: 17, Byte: 129},
385+
End: hcl.Pos{Line: 9, Column: 48, Byte: 160},
386+
},
387+
})
388+
},
389+
},
390+
322391
"destroy run": {
323392
module: map[string]string{
324393
"main.tf": `

internal/terraform/node_resource_validate.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,21 @@ func validateDependsOn(ctx EvalContext, dependsOn []hcl.Traversal) (diags tfdiag
811811
})
812812
}
813813

814+
// We don't allow depends_on on actions because their ordering is depending on the resource
815+
// that triggers them, therefore users should use a depends_on on the resource instead.
816+
817+
if ref != nil {
818+
switch ref.Subject.(type) {
819+
case addrs.Action, addrs.ActionInstance:
820+
diags = diags.Append(&hcl.Diagnostic{
821+
Severity: hcl.DiagError,
822+
Summary: "Invalid depends_on reference",
823+
Detail: "Actions can not be referenced in depends_on. Use depends_on on the resource that triggers the action instead.",
824+
Subject: traversal.SourceRange().Ptr(),
825+
})
826+
}
827+
}
828+
814829
// The ref must also refer to something that exists. To test that,
815830
// we'll just eval it and count on the fact that our evaluator will
816831
// detect references to non-existent objects.

0 commit comments

Comments
 (0)