terraform: show each tainted ID

This commit is contained in:
Armon Dadgar 2014-09-19 15:04:21 -07:00
parent ff42a92636
commit 8e421caba1
3 changed files with 78 additions and 7 deletions

View File

@ -1939,6 +1939,57 @@ func TestContextPlan_taint(t *testing.T) {
} }
} }
func TestContextPlan_multiple_taint(t *testing.T) {
c := testConfig(t, "plan-taint")
p := testProvider("aws")
p.DiffFn = testDiffFn
s := &State{
Modules: []*ModuleState{
&ModuleState{
Path: rootModulePath,
Resources: map[string]*ResourceState{
"aws_instance.foo": &ResourceState{
Type: "aws_instance",
Primary: &InstanceState{
ID: "bar",
Attributes: map[string]string{"num": "2"},
},
},
"aws_instance.bar": &ResourceState{
Type: "aws_instance",
Tainted: []*InstanceState{
&InstanceState{
ID: "baz",
},
&InstanceState{
ID: "zip",
},
},
},
},
},
},
}
ctx := testContext(t, &ContextOpts{
Config: c,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
State: s,
})
plan, err := ctx.Plan(nil)
if err != nil {
t.Fatalf("err: %s", err)
}
actual := strings.TrimSpace(plan.String())
expected := strings.TrimSpace(testTerraformPlanMultipleTaintStr)
if actual != expected {
t.Fatalf("bad:\n%s", actual)
}
}
func TestContextPlan_varMultiCountOne(t *testing.T) { func TestContextPlan_varMultiCountOne(t *testing.T) {
c := testConfig(t, "plan-var-multi-count-one") c := testConfig(t, "plan-var-multi-count-one")
p := testProvider("aws") p := testProvider("aws")

View File

@ -125,11 +125,7 @@ func (s *State) String() string {
id = rs.Primary.ID id = rs.Primary.ID
} }
if id == "" { if id == "" {
if len(rs.Tainted) > 0 { id = "<not created>"
id = rs.Tainted[0].ID
} else {
id = "<not created>"
}
} }
taintStr := "" taintStr := ""
@ -159,6 +155,10 @@ func (s *State) String() string {
buf.WriteString(fmt.Sprintf(" %s = %s\n", ak, av)) buf.WriteString(fmt.Sprintf(" %s = %s\n", ak, av))
} }
for idx, t := range rs.Tainted {
buf.WriteString(fmt.Sprintf(" Tainted ID %d = %s\n", idx+1, t.ID))
}
if len(rs.Dependencies) > 0 { if len(rs.Dependencies) > 0 {
buf.WriteString(fmt.Sprintf("\n Dependencies:\n")) buf.WriteString(fmt.Sprintf("\n Dependencies:\n"))
for _, dep := range rs.Dependencies { for _, dep := range rs.Dependencies {

View File

@ -138,7 +138,8 @@ aws_instance.foo:
const testTerraformApplyProvisionerFailStr = ` const testTerraformApplyProvisionerFailStr = `
aws_instance.bar: (1 tainted) aws_instance.bar: (1 tainted)
ID = foo ID = <not created>
Tainted ID 1 = foo
aws_instance.foo: aws_instance.foo:
ID = foo ID = foo
num = 2 num = 2
@ -501,7 +502,26 @@ DESTROY/CREATE: aws_instance.bar
STATE: STATE:
aws_instance.bar: (1 tainted) aws_instance.bar: (1 tainted)
ID = baz ID = <not created>
Tainted ID 1 = baz
aws_instance.foo:
ID = bar
num = 2
`
const testTerraformPlanMultipleTaintStr = `
DIFF:
DESTROY/CREATE: aws_instance.bar
foo: "" => "2"
type: "" => "aws_instance"
STATE:
aws_instance.bar: (2 tainted)
ID = <not created>
Tainted ID 1 = baz
Tainted ID 2 = zip
aws_instance.foo: aws_instance.foo:
ID = bar ID = bar
num = 2 num = 2