Skip to content

Commit

Permalink
command/show (plan -json): fix panic (#21541)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
mildwonkey committed Jun 3, 2019
1 parent ebc2e5f commit 65fc037
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 27 deletions.
16 changes: 1 addition & 15 deletions command/jsonplan/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion command/jsonplan/values_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 0 additions & 2 deletions command/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package command

import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
Expand Down Expand Up @@ -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))
}

Expand Down
7 changes: 2 additions & 5 deletions command/test-fixtures/show-json/basic-delete/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@
"ami": "bar",
"id": "placeholder"
},
"after_unknown": {
"ami": false,
"id": false
}
"after_unknown": {}
}
},
{
Expand All @@ -69,7 +66,7 @@
"id": "placeholder"
},
"after": null,
"after_unknown": false
"after_unknown": {}
}
}
],
Expand Down
5 changes: 1 addition & 4 deletions command/test-fixtures/show-json/basic-update/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@
"ami": "bar",
"id": "placeholder"
},
"after_unknown": {
"ami": false,
"id": false
}
"after_unknown": {}
}
}
],
Expand Down

0 comments on commit 65fc037

Please sign in to comment.