From 6a20e8927d52ee4f28dcc0798aa899bec81233dd Mon Sep 17 00:00:00 2001 From: James Nugent Date: Tue, 10 May 2016 14:56:26 -0400 Subject: [PATCH] core: Fix issues from rebasing dev-0.7 onto master - Fix sensitive outputs for lists and maps - Fix test prelude which was missed during conflict resolution - Fix `terraform output` to match old behaviour and not have outputs header and colouring - Bump timeout on TestAtlasClient_UnresolvableConflict --- command/apply.go | 17 +++++++++++------ command/apply_test.go | 11 ++++++++++- command/output.go | 2 +- command/refresh.go | 2 +- state/remote/atlas_test.go | 2 +- terraform/context_apply_test.go | 5 ++++- 6 files changed, 28 insertions(+), 11 deletions(-) diff --git a/command/apply.go b/command/apply.go index c61f84d4e..5598d5c35 100644 --- a/command/apply.go +++ b/command/apply.go @@ -251,7 +251,7 @@ func (c *ApplyCommand) Run(args []string) int { } if !c.Destroy { - if outputs := outputsAsString(state, ctx.Module().Config().Outputs); outputs != "" { + if outputs := outputsAsString(state, ctx.Module().Config().Outputs, true); outputs != "" { c.Ui.Output(c.Colorize().Color(outputs)) } } @@ -377,7 +377,7 @@ Options: return strings.TrimSpace(helpText) } -func outputsAsString(state *terraform.State, schema []*config.Output) string { +func outputsAsString(state *terraform.State, schema []*config.Output, includeHeader bool) string { if state == nil { return "" } @@ -386,11 +386,15 @@ func outputsAsString(state *terraform.State, schema []*config.Output) string { outputBuf := new(bytes.Buffer) if len(outputs) > 0 { schemaMap := make(map[string]*config.Output) - for _, s := range schema { - schemaMap[s.Name] = s + if schema != nil { + for _, s := range schema { + schemaMap[s.Name] = s + } } - outputBuf.WriteString("[reset][bold][green]\nOutputs:\n\n") + if includeHeader { + outputBuf.WriteString("[reset][bold][green]\nOutputs:\n\n") + } // Output the outputs in alphabetical order keyLen := 0 @@ -404,7 +408,8 @@ func outputsAsString(state *terraform.State, schema []*config.Output) string { sort.Strings(ks) for _, k := range ks { - if schemaMap[k].Sensitive { + schema, ok := schemaMap[k] + if ok && schema.Sensitive { outputBuf.WriteString(fmt.Sprintf("%s = \n", k)) continue } diff --git a/command/apply_test.go b/command/apply_test.go index 01b9fbd8e..b847a769d 100644 --- a/command/apply_test.go +++ b/command/apply_test.go @@ -887,6 +887,15 @@ func TestApply_stateNoExist(t *testing.T) { } func TestApply_sensitiveOutput(t *testing.T) { + p := testProvider() + ui := new(cli.MockUi) + c := &ApplyCommand{ + Meta: Meta{ + ContextOpts: testCtxConfig(p), + Ui: ui, + }, + } + statePath := testTempFile(t) args := []string{ @@ -902,7 +911,7 @@ func TestApply_sensitiveOutput(t *testing.T) { if !strings.Contains(output, "notsensitive = Hello world") { t.Fatalf("bad: output should contain 'notsensitive' output\n%s", output) } - if !strings.Contains(output, "sensitive = ") { + if !strings.Contains(output, "sensitive = ") { t.Fatalf("bad: output should contain 'sensitive' output\n%s", output) } } diff --git a/command/output.go b/command/output.go index d031dfb3e..5808bae77 100644 --- a/command/output.go +++ b/command/output.go @@ -81,7 +81,7 @@ func (c *OutputCommand) Run(args []string) int { } if name == "" { - c.Ui.Output(outputsAsString(state)) + c.Ui.Output(outputsAsString(state, nil, false)) return 0 } diff --git a/command/refresh.go b/command/refresh.go index 7a6f7f9c3..0c41bcbe4 100644 --- a/command/refresh.go +++ b/command/refresh.go @@ -109,7 +109,7 @@ func (c *RefreshCommand) Run(args []string) int { return 1 } - if outputs := outputsAsString(newState, ctx.Module().Config().Outputs); outputs != "" { + if outputs := outputsAsString(newState, ctx.Module().Config().Outputs, true); outputs != "" { c.Ui.Output(c.Colorize().Color(outputs)) } diff --git a/state/remote/atlas_test.go b/state/remote/atlas_test.go index 4deea7a3f..5a58f9c79 100644 --- a/state/remote/atlas_test.go +++ b/state/remote/atlas_test.go @@ -159,7 +159,7 @@ func TestAtlasClient_UnresolvableConflict(t *testing.T) { select { case <-doneCh: // OK - case <-time.After(50 * time.Millisecond): + case <-time.After(500 * time.Millisecond): t.Fatalf("Timed out after 50ms, probably because retrying infinitely.") } } diff --git a/terraform/context_apply_test.go b/terraform/context_apply_test.go index 574562c4f..fe030b2c6 100644 --- a/terraform/context_apply_test.go +++ b/terraform/context_apply_test.go @@ -2598,11 +2598,14 @@ func TestContext2Apply_destroyModuleWithAttrsReferencingResource(t *testing.T) { t.Fatalf("err: %s", err) } - ctx = planFromFile.Context(&ContextOpts{ + ctx, err = planFromFile.Context(&ContextOpts{ Providers: map[string]ResourceProviderFactory{ "aws": testProviderFuncFixed(p), }, }) + if err != nil { + t.Fatalf("err: %s", err) + } state, err = ctx.Apply() if err != nil {