parent
edd67547bc
commit
d5a941a0a4
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue