From 68b07a766a0f40d0d0e5ee30e14ab2e527c9d2ad Mon Sep 17 00:00:00 2001 From: James Bardin Date: Wed, 8 Nov 2017 11:10:32 -0500 Subject: [PATCH] add failing test for orphaned modules outputs When an entire module is removed from the config, that module's outputs are not removed from the state. --- terraform/context_apply_test.go | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/terraform/context_apply_test.go b/terraform/context_apply_test.go index 0940290448..04f8b1db21 100644 --- a/terraform/context_apply_test.go +++ b/terraform/context_apply_test.go @@ -4036,7 +4036,7 @@ func TestContext2Apply_outputOrphanModule(t *testing.T) { "aws": testProviderFuncFixed(p), }, ), - State: state, + State: state.DeepCopy(), }) if _, err := ctx.Plan(); err != nil { @@ -4051,7 +4051,34 @@ func TestContext2Apply_outputOrphanModule(t *testing.T) { actual := strings.TrimSpace(state.String()) expected := strings.TrimSpace(testTerraformApplyOutputOrphanModuleStr) if actual != expected { - t.Fatalf("bad: \n%s", actual) + t.Fatalf("expected:\n%s\n\ngot:\n%s", expected, actual) + } + + // now apply with no module in the config, which should remove the + // remaining output + ctx = testContext2(t, &ContextOpts{ + Module: module.NewEmptyTree(), + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), + State: state.DeepCopy(), + }) + + if _, err := ctx.Plan(); err != nil { + t.Fatalf("err: %s", err) + } + + state, err = ctx.Apply() + if err != nil { + t.Fatalf("err: %s", err) + } + + expected = "" + actual = strings.TrimSpace(state.String()) + if actual != expected { + t.Fatalf("expected:\n%s\n\ngot:\n%s", expected, actual) } }