Merge pull request #8167 from hashicorp/b-tainted-no-attrs-still-replaces

terraform: diffs with only tainted set are non-empty
This commit is contained in:
Paul Hinze 2016-08-12 18:06:32 -05:00 committed by GitHub
commit b9f950f1d4
4 changed files with 36 additions and 2 deletions

View File

@ -2400,6 +2400,26 @@ func TestSchemaMap_Diff(t *testing.T) {
Err: false, Err: false,
}, },
"tainted in state w/ no attr changes is still a replacement": {
Schema: map[string]*Schema{},
State: &terraform.InstanceState{
Attributes: map[string]string{
"id": "someid",
},
Tainted: true,
},
Config: map[string]interface{}{},
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{},
DestroyTainted: true,
},
Err: false,
},
} }
for tn, tc := range cases { for tn, tc := range cases {

View File

@ -1950,6 +1950,7 @@ func TestContext2Plan_taintDestroyInterpolatedCountRace(t *testing.T) {
DIFF: DIFF:
DESTROY/CREATE: aws_instance.foo.0 DESTROY/CREATE: aws_instance.foo.0
type: "" => "aws_instance"
STATE: STATE:
@ -1961,7 +1962,7 @@ aws_instance.foo.2:
ID = bar ID = bar
`) `)
if actual != expected { if actual != expected {
t.Fatalf("bad:\n%s", actual) t.Fatalf("[%d] bad:\n%s\nexpected:\n%s\n", i, actual, expected)
} }
} }
} }

View File

@ -361,7 +361,7 @@ func (d *InstanceDiff) Empty() bool {
d.mu.Lock() d.mu.Lock()
defer d.mu.Unlock() defer d.mu.Unlock()
return !d.Destroy && len(d.Attributes) == 0 return !d.Destroy && !d.DestroyTainted && len(d.Attributes) == 0
} }
func (d *InstanceDiff) GoString() string { func (d *InstanceDiff) GoString() string {

View File

@ -27,6 +27,19 @@ func TestDiffEmpty(t *testing.T) {
} }
} }
func TestDiffEmpty_taintedIsNotEmpty(t *testing.T) {
diff := new(Diff)
mod := diff.AddModule(rootModulePath)
mod.Resources["nodeA"] = &InstanceDiff{
DestroyTainted: true,
}
if diff.Empty() {
t.Fatal("should not be empty, since DestroyTainted was set")
}
}
func TestModuleDiff_ChangeType(t *testing.T) { func TestModuleDiff_ChangeType(t *testing.T) {
cases := []struct { cases := []struct {
Diff *ModuleDiff Diff *ModuleDiff