terraform: require the prefix match with a "." in Diff.Instances
This commit is contained in:
parent
b43ca0aa52
commit
ab6741f6fc
|
@ -172,8 +172,10 @@ func (d *ModuleDiff) Empty() bool {
|
|||
func (d *ModuleDiff) Instances(id string) []*InstanceDiff {
|
||||
var result []*InstanceDiff
|
||||
for k, diff := range d.Resources {
|
||||
if strings.HasPrefix(k, id) && !diff.Empty() {
|
||||
result = append(result, diff)
|
||||
if k == id || strings.HasPrefix(k, id+".") {
|
||||
if !diff.Empty() {
|
||||
result = append(result, diff)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package terraform
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
@ -268,6 +269,68 @@ func TestInstanceDiff_Empty(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestModuleDiff_Instances(t *testing.T) {
|
||||
yesDiff := &InstanceDiff{Destroy: true}
|
||||
noDiff := &InstanceDiff{Destroy: true, DestroyTainted: true}
|
||||
|
||||
cases := []struct {
|
||||
Diff *ModuleDiff
|
||||
Id string
|
||||
Result []*InstanceDiff
|
||||
}{
|
||||
{
|
||||
&ModuleDiff{
|
||||
Resources: map[string]*InstanceDiff{
|
||||
"foo": yesDiff,
|
||||
"bar": noDiff,
|
||||
},
|
||||
},
|
||||
"foo",
|
||||
[]*InstanceDiff{
|
||||
yesDiff,
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
&ModuleDiff{
|
||||
Resources: map[string]*InstanceDiff{
|
||||
"foo": yesDiff,
|
||||
"foo.0": yesDiff,
|
||||
"bar": noDiff,
|
||||
},
|
||||
},
|
||||
"foo",
|
||||
[]*InstanceDiff{
|
||||
yesDiff,
|
||||
yesDiff,
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
&ModuleDiff{
|
||||
Resources: map[string]*InstanceDiff{
|
||||
"foo": yesDiff,
|
||||
"foo.0": yesDiff,
|
||||
"foo_bar": noDiff,
|
||||
"bar": noDiff,
|
||||
},
|
||||
},
|
||||
"foo",
|
||||
[]*InstanceDiff{
|
||||
yesDiff,
|
||||
yesDiff,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for i, tc := range cases {
|
||||
actual := tc.Diff.Instances(tc.Id)
|
||||
if !reflect.DeepEqual(actual, tc.Result) {
|
||||
t.Fatalf("%d: %#v", i, actual)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestInstanceDiff_RequiresNew(t *testing.T) {
|
||||
rd := &InstanceDiff{
|
||||
Attributes: map[string]*ResourceAttrDiff{
|
||||
|
|
Loading…
Reference in New Issue