Skip to content

Commit

Permalink
Merge pull request #7589 from hashicorp/b-data-source-plan-counts
Browse files Browse the repository at this point in the history
command: Do not count data sources in plan totals
  • Loading branch information
jen20 authored Jul 12, 2016
2 parents 6cc47c3 + d5a941a commit 1ca51ab
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
6 changes: 6 additions & 0 deletions command/hook_count.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package command

import (
"strings"
"sync"

"github.com/hashicorp/terraform/terraform"
Expand Down Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions command/hook_count_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 1ca51ab

Please sign in to comment.