From 05cbb5c0ea15b420f585b319c4df03c16c5a17e7 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 17 Aug 2016 18:54:18 -0500 Subject: [PATCH] terraform: add test for filtering nested modules --- terraform/state_filter_test.go | 14 ++++++ .../state-filter/nested-modules.tfstate | 47 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 terraform/test-fixtures/state-filter/nested-modules.tfstate 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": {} + } + } + } + } + ] +}