diff --git a/terraform/context_apply_test.go b/terraform/context_apply_test.go index 23093ee70..b5700e715 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 da3f01e0e..0d303b0fe 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()