From 6106c62069228d5f8278275adeb3d6bd244fd51d Mon Sep 17 00:00:00 2001 From: Kristin Laemmert Date: Fri, 31 May 2019 11:07:35 -0500 Subject: [PATCH] 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 | 12 +----------- command/jsonplan/values_test.go | 2 +- command/show_test.go | 2 -- .../test-fixtures/show-json/basic-delete/output.json | 7 ++----- .../test-fixtures/show-json/basic-update/output.json | 5 +---- 5 files changed, 5 insertions(+), 23 deletions(-) diff --git a/command/jsonplan/plan.go b/command/jsonplan/plan.go index 0dffb7110c8c..93980fbac0db 100644 --- a/command/jsonplan/plan.go +++ b/command/jsonplan/plan.go @@ -210,17 +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.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 ca02b543ad64..6b04dba02cae 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 30f5bba71279..9fca88b007dd 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 36b5c6946ec5..874e2d86d82c 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 29f2f4cfdd51..5f46ecc10fbe 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": {} } } ],