diff --git a/terraform/state_filter_test.go b/terraform/state_filter_test.go index 5e66d9176..55a8baeb7 100644 --- a/terraform/state_filter_test.go +++ b/terraform/state_filter_test.go @@ -92,6 +92,20 @@ func TestStateFilterFilter(t *testing.T) { "*terraform.InstanceState: module.consul.aws_instance.consul-green[0]", }, }, + + "nested modules": { + "nested-modules.tfstate", + []string{"module.outer"}, + []string{ + "*terraform.ModuleState: module.outer", + "*terraform.ModuleState: module.outer.module.child1", + "*terraform.ResourceState: module.outer.module.child1.aws_instance.foo", + "*terraform.InstanceState: module.outer.module.child1.aws_instance.foo", + "*terraform.ModuleState: module.outer.module.child2", + "*terraform.ResourceState: module.outer.module.child2.aws_instance.foo", + "*terraform.InstanceState: module.outer.module.child2.aws_instance.foo", + }, + }, } for n, tc := range cases { diff --git a/terraform/test-fixtures/state-filter/nested-modules.tfstate b/terraform/test-fixtures/state-filter/nested-modules.tfstate new file mode 100644 index 000000000..282c390af --- /dev/null +++ b/terraform/test-fixtures/state-filter/nested-modules.tfstate @@ -0,0 +1,47 @@ +{ + "version": 1, + "serial": 12, + "modules": [ + { + "path": [ + "root", + "outer" + ], + "resources": {} + }, + { + "path": [ + "root", + "outer", + "child1" + ], + "resources": { + "aws_instance.foo": { + "type": "aws_instance", + "depends_on": [], + "primary": { + "id": "1", + "attributes": {} + } + } + } + }, + { + "path": [ + "root", + "outer", + "child2" + ], + "resources": { + "aws_instance.foo": { + "type": "aws_instance", + "depends_on": [], + "primary": { + "id": "1", + "attributes": {} + } + } + } + } + ] +}