From aedbbc62071f4dadc567df6b842d3fb2a2967194 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Tue, 29 May 2018 16:56:00 -0700 Subject: [PATCH] core: Fix TestContext2Apply_outputOrphanModule The adaptation of ModuleState.RemovedOutputs for the new config types was incorrect because it took the absence of any output map as "nothing to do", rather than "everything has been removed" as expected. Now it treats a nil map like an empty map, detecting _all_ of the outputs as having been removed if the output map is nil. --- terraform/context_apply_test.go | 2 +- terraform/state.go | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/terraform/context_apply_test.go b/terraform/context_apply_test.go index 23093ee704..b5700e7151 100644 --- a/terraform/context_apply_test.go +++ b/terraform/context_apply_test.go @@ -4110,7 +4110,7 @@ func TestContext2Apply_outputOrphanModule(t *testing.T) { actual = strings.TrimSpace(state.String()) if actual != "" { - t.Fatalf("expected no state, got:\n%s", actual) + t.Fatalf("wrong result\n\ngot:\n%s\n\nwant: no state at all", actual) } } diff --git a/terraform/state.go b/terraform/state.go index da3f01e0ee..0d303b0fef 100644 --- a/terraform/state.go +++ b/terraform/state.go @@ -1086,9 +1086,13 @@ func (m *ModuleState) Orphans(c *configs.Module) []addrs.ResourceInstance { // RemovedOutputs returns a list of outputs that are in the State but aren't // present in the configuration itself. func (s *ModuleState) RemovedOutputs(outputs map[string]*configs.Output) []addrs.OutputValue { - if len(outputs) == 0 { - return nil + if outputs == nil { + // If we got no output map at all then we'll just treat our set of + // configured outputs as empty, since that suggests that they've all + // been removed by removing their containing module. + outputs = make(map[string]*configs.Output) } + s.Lock() defer s.Unlock()