command: Do not count data sources in plan totals

Fixes #7483
This commit is contained in:
Paul Hinze 2016-07-11 16:35:01 -05:00
parent edd67547bc
commit d5a941a0a4
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
2 changed files with 40 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package command package command
import ( import (
"strings"
"sync" "sync"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
@ -90,6 +91,11 @@ func (h *CountHook) PostDiff(
h.Lock() h.Lock()
defer h.Unlock() defer h.Unlock()
// We don't count anything for data sources
if strings.HasPrefix(n.Id, "data.") {
return terraform.HookActionContinue, nil
}
switch d.ChangeType() { switch d.ChangeType() {
case terraform.DiffDestroyCreate: case terraform.DiffDestroyCreate:
h.ToRemoveAndAdd += 1 h.ToRemoveAndAdd += 1

View File

@ -182,3 +182,37 @@ func TestCountHookPostDiff_NoChange(t *testing.T) {
expected, h) expected, h)
} }
} }
func TestCountHookPostDiff_DataSource(t *testing.T) {
h := new(CountHook)
resources := map[string]*terraform.InstanceDiff{
"data.foo": &terraform.InstanceDiff{
Destroy: true,
},
"data.bar": &terraform.InstanceDiff{},
"data.lorem": &terraform.InstanceDiff{
Destroy: false,
Attributes: map[string]*terraform.ResourceAttrDiff{
"foo": &terraform.ResourceAttrDiff{},
},
},
"data.ipsum": &terraform.InstanceDiff{Destroy: true},
}
for k, d := range resources {
n := &terraform.InstanceInfo{Id: k}
h.PostDiff(n, d)
}
expected := new(CountHook)
expected.ToAdd = 0
expected.ToChange = 0
expected.ToRemoveAndAdd = 0
expected.ToRemove = 0
if !reflect.DeepEqual(expected, h) {
t.Fatalf("Expected %#v, got %#v instead.",
expected, h)
}
}