Merge pull request #32840 from hashicorp/jbardin/render-output-crash

Prevent nil Colorize options when rendering state outputs
This commit is contained in:
James Bardin 2023-03-14 14:28:03 -04:00 committed by GitHub
commit ccb376a189
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 8 deletions

View File

@ -81,10 +81,9 @@ func (renderer Renderer) RenderHumanState(state State) {
return return
} }
opts := computed.RenderHumanOpts{ opts := computed.NewRenderHumanOpts(renderer.Colorize)
ShowUnchangedChildren: true, opts.ShowUnchangedChildren = true
HideDiffActionSymbols: true, opts.HideDiffActionSymbols = true
}
state.renderHumanStateModule(renderer, state.RootModule, opts, true) state.renderHumanStateModule(renderer, state.RootModule, opts, true)
state.renderHumanStateOutputs(renderer, opts) state.renderHumanStateOutputs(renderer, opts)
@ -119,11 +118,11 @@ func (r Renderer) RenderLog(log *JSONLog) error {
return err return err
} }
opts := computed.NewRenderHumanOpts(r.Colorize)
opts.ShowUnchangedChildren = true
outputDiff := change.ComputeDiffForType(ctype) outputDiff := change.ComputeDiffForType(ctype)
outputStr := outputDiff.RenderHuman(0, computed.RenderHumanOpts{ outputStr := outputDiff.RenderHuman(0, opts)
Colorize: r.Colorize,
ShowUnchangedChildren: true,
})
msg := fmt.Sprintf("%s = %s", name, outputStr) msg := fmt.Sprintf("%s = %s", name, outputStr)
r.Streams.Println(msg) r.Streams.Println(msg)

View File

@ -447,6 +447,13 @@ func TestShow_plan_json(t *testing.T) {
func TestShow_state(t *testing.T) { func TestShow_state(t *testing.T) {
originalState := testState() originalState := testState()
root := originalState.RootModule()
root.SetOutputValue("test", cty.ObjectVal(map[string]cty.Value{
"attr": cty.NullVal(cty.DynamicPseudoType),
"null": cty.NullVal(cty.String),
"list": cty.ListVal([]cty.Value{cty.NullVal(cty.Number)}),
}), false)
statePath := testStateFile(t, originalState) statePath := testStateFile(t, originalState)
defer os.RemoveAll(filepath.Dir(statePath)) defer os.RemoveAll(filepath.Dir(statePath))