Merge pull request #7589 from hashicorp/b-data-source-plan-counts

command: Do not count data sources in plan totals
This commit is contained in:
James Nugent 2016-07-12 11:56:31 -06:00 committed by GitHub
commit 1ca51ab454
2 changed files with 40 additions and 0 deletions

View File

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

View File

@ -182,3 +182,37 @@ func TestCountHookPostDiff_NoChange(t *testing.T) {
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)
}
}