terraform: make sure taint destroys happen first for counts

This commit is contained in:
Mitchell Hashimoto 2014-10-12 09:50:25 -07:00
parent 7af9179edd
commit 06889b8fc7
2 changed files with 53 additions and 2 deletions

View File

@ -1088,10 +1088,16 @@ func graphAddTainted(g *depgraph.Graph, mod *ModuleState) {
continue
}
// Find the untainted resource of this in the noun list
// Find the untainted resource of this in the noun list. If our
// name is 3 parts, then we mus be a count instance, so our
// untainted node is just the noun without the count.
var untainted *depgraph.Noun
untaintedK := k
if ps := strings.Split(k, "."); len(ps) == 3 {
untaintedK = strings.Join(ps[0:2], ".")
}
for _, n := range g.Nouns {
if n.Name == k {
if n.Name == untaintedK {
untainted = n
break
}

View File

@ -43,6 +43,38 @@ func TestGraph_count(t *testing.T) {
}
}
func TestGraph_countTainted(t *testing.T) {
m := testModule(t, "graph-count")
state := &State{
Modules: []*ModuleState{
&ModuleState{
Path: []string{"root"},
Resources: map[string]*ResourceState{
"aws_instance.web.0": &ResourceState{
Type: "aws_instance",
Tainted: []*InstanceState{
&InstanceState{
ID: "foo",
},
},
},
},
},
},
}
g, err := Graph(&GraphOpts{Module: m, State: state})
if err != nil {
t.Fatalf("err: %s", err)
}
actual := strings.TrimSpace(g.String())
expected := strings.TrimSpace(testTerraformGraphCountTaintedStr)
if actual != expected {
t.Fatalf("bad:\n\n%s", actual)
}
}
func TestGraph_varResource(t *testing.T) {
m := testModule(t, "graph-count-var-resource")
@ -1069,6 +1101,19 @@ root
root -> aws_load_balancer.weblb
`
const testTerraformGraphCountTaintedStr = `
root: root
aws_instance.web
aws_instance.web -> aws_instance.web.0 (tainted #1)
aws_instance.web.0 (tainted #1)
aws_load_balancer.weblb
aws_load_balancer.weblb -> aws_instance.web
root
root -> aws_instance.web
root -> aws_instance.web.0 (tainted #1)
root -> aws_load_balancer.weblb
`
const testTerraformGraphCountVarResourceStr = `
root: root
aws_instance.foo