Skip to content

Commit

Permalink
Merge pull request #8167 from hashicorp/b-tainted-no-attrs-still-repl…
Browse files Browse the repository at this point in the history
…aces

terraform: diffs with only tainted set are non-empty
  • Loading branch information
phinze authored Aug 12, 2016
2 parents 81ea297 + 3dccfa0 commit b9f950f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
20 changes: 20 additions & 0 deletions helper/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2400,6 +2400,26 @@ func TestSchemaMap_Diff(t *testing.T) {

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 {
Expand Down
3 changes: 2 additions & 1 deletion terraform/context_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1950,6 +1950,7 @@ func TestContext2Plan_taintDestroyInterpolatedCountRace(t *testing.T) {
DIFF:
DESTROY/CREATE: aws_instance.foo.0
type: "" => "aws_instance"
STATE:
Expand All @@ -1961,7 +1962,7 @@ aws_instance.foo.2:
ID = bar
`)
if actual != expected {
t.Fatalf("bad:\n%s", actual)
t.Fatalf("[%d] bad:\n%s\nexpected:\n%s\n", i, actual, expected)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion terraform/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ func (d *InstanceDiff) Empty() bool {

d.mu.Lock()
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 {
Expand Down
13 changes: 13 additions & 0 deletions terraform/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
cases := []struct {
Diff *ModuleDiff
Expand Down

0 comments on commit b9f950f

Please sign in to comment.