From 65fc037ecb4678ac412e956391b5c9a82beee021 Mon Sep 17 00:00:00 2001 From: Kristin Laemmert Date: Mon, 3 Jun 2019 07:14:23 -0500 Subject: [PATCH] command/show (plan -json): fix panic (#21541) * command/show -json: fix panic afterUnknown should return only bools, not values. * command/jsonplan: let's delete some redundant code! the plan output was somewhat inconsistent with return values for "after_unknown". This strives to fix that. If all "after" values are known, return an empty object instead of iterating over values. Also fixing some typos and general copypasta. --- command/jsonplan/plan.go | 16 +--------------- command/jsonplan/values_test.go | 2 +- command/show_test.go | 2 -- .../show-json/basic-delete/output.json | 7 ++----- .../show-json/basic-update/output.json | 5 +---- 5 files changed, 5 insertions(+), 27 deletions(-) diff --git a/command/jsonplan/plan.go b/command/jsonplan/plan.go index f02c8ae0b..93980fbac 100644 --- a/command/jsonplan/plan.go +++ b/command/jsonplan/plan.go @@ -210,21 +210,7 @@ func (p *plan) marshalResourceChanges(changes *plans.Changes, schemas *terraform if err != nil { return err } - afterUnknown, _ = cty.Transform(changeV.After, func(path cty.Path, val cty.Value) (cty.Value, error) { - if val.IsNull() { - return cty.False, nil - } - - if !val.Type().IsPrimitiveType() { - return val, nil // just pass through non-primitives; they already contain our transform results - } - - if val.IsKnown() { - return cty.False, nil - } - - return cty.True, nil - }) + afterUnknown = cty.EmptyObjectVal } else { filteredAfter := omitUnknowns(changeV.After) if filteredAfter.IsNull() { diff --git a/command/jsonplan/values_test.go b/command/jsonplan/values_test.go index ca02b543a..6b04dba02 100644 --- a/command/jsonplan/values_test.go +++ b/command/jsonplan/values_test.go @@ -173,7 +173,7 @@ func TestMarshalPlanResources(t *testing.T) { Want []resource Err bool }{ - "create with unkonwns": { + "create with unknowns": { Action: plans.Create, Before: cty.NullVal(cty.EmptyObject), After: cty.ObjectVal(map[string]cty.Value{ diff --git a/command/show_test.go b/command/show_test.go index 30f5bba71..9fca88b00 100644 --- a/command/show_test.go +++ b/command/show_test.go @@ -2,7 +2,6 @@ package command import ( "encoding/json" - "fmt" "io/ioutil" "os" "path/filepath" @@ -221,7 +220,6 @@ func TestShow_json_output(t *testing.T) { json.Unmarshal([]byte(byteValue), &want) if !cmp.Equal(got, want) { - fmt.Println(ui.OutputWriter.String()) t.Fatalf("wrong result:\n %v\n", cmp.Diff(got, want)) } diff --git a/command/test-fixtures/show-json/basic-delete/output.json b/command/test-fixtures/show-json/basic-delete/output.json index 36b5c6946..874e2d86d 100644 --- a/command/test-fixtures/show-json/basic-delete/output.json +++ b/command/test-fixtures/show-json/basic-delete/output.json @@ -48,10 +48,7 @@ "ami": "bar", "id": "placeholder" }, - "after_unknown": { - "ami": false, - "id": false - } + "after_unknown": {} } }, { @@ -69,7 +66,7 @@ "id": "placeholder" }, "after": null, - "after_unknown": false + "after_unknown": {} } } ], diff --git a/command/test-fixtures/show-json/basic-update/output.json b/command/test-fixtures/show-json/basic-update/output.json index 29f2f4cfd..5f46ecc10 100644 --- a/command/test-fixtures/show-json/basic-update/output.json +++ b/command/test-fixtures/show-json/basic-update/output.json @@ -48,10 +48,7 @@ "ami": "bar", "id": "placeholder" }, - "after_unknown": { - "ami": false, - "id": false - } + "after_unknown": {} } } ],