terraform: fix some issues around filtering single counts

This commit is contained in:
Mitchell Hashimoto 2016-03-25 10:01:18 -07:00 committed by James Nugent
parent d1b46e99bd
commit a754723561
2 changed files with 15 additions and 1 deletions

View File

@ -36,7 +36,7 @@ func (f *StateFilter) Filter(fs ...string) ([]*StateFilterResult, error) {
// If we werent given any filters, then we list all
if len(fs) == 0 {
as = append(as, &ResourceAddress{})
as = append(as, &ResourceAddress{Index: -1})
}
// Filter each of the address. We keep track of this in a map to
@ -94,6 +94,11 @@ func (f *StateFilter) filterSingle(a *ResourceAddress) []*StateFilterResult {
continue
}
if a.Index >= 0 && key.Index != a.Index {
// Index doesn't match
continue
}
// Build the address for this resource
addr := &ResourceAddress{
Path: m.Path[1:],

View File

@ -51,6 +51,15 @@ func TestStateFilterFilter(t *testing.T) {
"*terraform.InstanceState: module.bootstrap.aws_route53_zone.oasis-consul-bootstrap",
},
},
"single count index": {
"complete.tfstate",
[]string{"module.consul.aws_instance.consul-green[0]"},
[]string{
"*terraform.ResourceState: module.consul.aws_instance.consul-green[0]",
"*terraform.InstanceState: module.consul.aws_instance.consul-green[0]",
},
},
}
for n, tc := range cases {