From 9d8ab5565841912873c22e78e7b0c176bfbd0c3c Mon Sep 17 00:00:00 2001 From: James Bardin Date: Thu, 28 Sep 2017 11:06:37 -0400 Subject: [PATCH] Add failing test for destroy with locals --- terraform/context_apply_test.go | 47 +++++++++++++++++++ .../apply-destroy-with-locals/main.tf | 8 ++++ 2 files changed, 55 insertions(+) create mode 100644 terraform/test-fixtures/apply-destroy-with-locals/main.tf diff --git a/terraform/context_apply_test.go b/terraform/context_apply_test.go index fc45c6ac0..32ce76391 100644 --- a/terraform/context_apply_test.go +++ b/terraform/context_apply_test.go @@ -8809,3 +8809,50 @@ module.child: t.Fatalf("wrong final state\ngot:\n%s\nwant:\n%s", got, want) } } + +func TestContext2Apply_destroyWithLocals(t *testing.T) { + m := testModule(t, "apply-destroy-with-locals") + ctx := testContext2(t, &ContextOpts{ + Module: m, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(testProvider("aws")), + }, + ), + State: &State{ + Modules: []*ModuleState{ + &ModuleState{ + Path: rootModulePath, + Outputs: map[string]*OutputState{ + "name": &OutputState{ + Type: "string", + Value: "test-bar", + }, + }, + Resources: map[string]*ResourceState{ + "aws_instance.foo": &ResourceState{ + Type: "aws_instance", + Primary: &InstanceState{ + ID: "foo", + }, + }, + }, + }, + }, + }, + Destroy: true, + }) + + state, err := ctx.Apply() + if err != nil { + t.Fatalf("error during apply: %s", err) + } + + got := strings.TrimSpace(state.String()) + want := strings.TrimSpace(` + TODO +`) + if got != want { + t.Fatalf("wrong final state\ngot:\n%s\nwant:\n%s", got, want) + } +} diff --git a/terraform/test-fixtures/apply-destroy-with-locals/main.tf b/terraform/test-fixtures/apply-destroy-with-locals/main.tf new file mode 100644 index 000000000..1ab751871 --- /dev/null +++ b/terraform/test-fixtures/apply-destroy-with-locals/main.tf @@ -0,0 +1,8 @@ +locals { + name = "test-${aws_instance.foo.id}" +} +resource "aws_instance" "foo" {} + +output "name" { + value = "${local.name}" +}