Merge pull request #9728 from hashicorp/b-prov-cycle

terraform: validate graph on resource expansation to catch cycles
This commit is contained in:
Mitchell Hashimoto 2016-10-31 13:24:10 -07:00 committed by GitHub
commit 144f31b6f2
3 changed files with 29 additions and 1 deletions

View File

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

View File

@ -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())
}

View 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}"
}
}