terraform: testing the destroy order of modules

This commit is contained in:
Armon Dadgar 2014-11-24 14:58:52 -08:00
parent afef564108
commit 3bdaccdf5d
3 changed files with 61 additions and 0 deletions

View File

@ -731,6 +731,42 @@ func TestGraphAddDiff_module(t *testing.T) {
}
}
func TestGraphAddDiff_module_depends(t *testing.T) {
m := testModule(t, "graph-diff-module-dep")
diff := &Diff{
Modules: []*ModuleDiff{
&ModuleDiff{
Path: rootModulePath,
Resources: map[string]*InstanceDiff{
"aws_instance.foo": &InstanceDiff{
Destroy: true,
},
},
},
&ModuleDiff{
Path: []string{"root", "child"},
Destroy: true,
Resources: map[string]*InstanceDiff{
"aws_instance.foo": &InstanceDiff{
Destroy: true,
},
},
},
},
}
g, err := Graph(&GraphOpts{Module: m, Diff: diff})
if err != nil {
t.Fatalf("err: %s", err)
}
actual := strings.TrimSpace(g.String())
expected := strings.TrimSpace(testTerraformGraphDiffModuleDependsStr)
if actual != expected {
t.Fatalf("bad:\n\n%s", actual)
}
}
func TestGraphAddDiff_createBeforeDestroy(t *testing.T) {
m := testModule(t, "graph-diff-create-before")
diff := &Diff{
@ -1214,6 +1250,18 @@ root
root -> module.child
`
const testTerraformGraphDiffModuleDependsStr = `
root: root
aws_instance.foo
aws_instance.foo -> aws_instance.foo (destroy)
aws_instance.foo (destroy)
aws_instance.foo (destroy) -> module.child
module.child
root
root -> aws_instance.foo
root -> module.child
`
const testTerraformGraphModulesStr = `
root: root
aws_instance.web

View File

@ -0,0 +1,5 @@
resource "aws_instance" "foo" {}
output "bar" {
value = "baz"
}

View File

@ -0,0 +1,8 @@
resource "aws_instance" "foo" {}
module "child" {
source = "./child"
in = "${aws_instance.foo.id}"
}