mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-26 00:41:27 -06:00
terraform: validate graph on resource expansation to catch cycles
Fixes #5342 The dynamically expanded subgraph wasn't being validated so cycles weren't being caught here and Terraform would just hang. This fixes that. Note that it may make sense to validate higher level when the graph is expanded but there are certain cases we actually expect the graph to potentially be invalid, so this seems safer for now.
This commit is contained in:
parent
6e55f5683c
commit
1aed6f8abb
@ -841,6 +841,27 @@ func TestContext2Plan_preventDestroy_destroyPlan(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestContext2Plan_provisionerCycle(t *testing.T) {
|
||||
m := testModule(t, "plan-provisioner-cycle")
|
||||
p := testProvider("aws")
|
||||
p.DiffFn = testDiffFn
|
||||
pr := testProvisioner()
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Module: m,
|
||||
Providers: map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
},
|
||||
Provisioners: map[string]ResourceProvisionerFactory{
|
||||
"local-exec": testProvisionerFuncFixed(pr),
|
||||
},
|
||||
})
|
||||
|
||||
_, err := ctx.Plan()
|
||||
if err == nil {
|
||||
t.Fatalf("should error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestContext2Plan_computed(t *testing.T) {
|
||||
m := testModule(t, "plan-computed")
|
||||
p := testProvider("aws")
|
||||
|
@ -188,7 +188,7 @@ func (n *GraphNodeConfigResource) DynamicExpand(ctx EvalContext) (*Graph, error)
|
||||
steps = append(steps, &RootTransformer{})
|
||||
|
||||
// Build the graph
|
||||
b := &BasicGraphBuilder{Steps: steps}
|
||||
b := &BasicGraphBuilder{Steps: steps, Validate: true}
|
||||
return b.Build(ctx.Path())
|
||||
}
|
||||
|
||||
|
7
terraform/test-fixtures/plan-provisioner-cycle/main.tf
Normal file
7
terraform/test-fixtures/plan-provisioner-cycle/main.tf
Normal file
@ -0,0 +1,7 @@
|
||||
resource "aws_instance" "foo" {
|
||||
count = 3
|
||||
|
||||
provisioner "local-exec" {
|
||||
command = "echo ${aws_instance.foo.0.id} ${aws_instance.foo.1.id} ${aws_instance.foo.2.id}"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user