diff --git a/terraform/state_filter.go b/terraform/state_filter.go index cb485416d..792fd2ab1 100644 --- a/terraform/state_filter.go +++ b/terraform/state_filter.go @@ -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:], diff --git a/terraform/state_filter_test.go b/terraform/state_filter_test.go index f58677a95..1f19dc1f1 100644 --- a/terraform/state_filter_test.go +++ b/terraform/state_filter_test.go @@ -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 {