Skip to content

Commit

Permalink
command/jsonplan: let's delete some redundant code!
Browse files Browse the repository at this point in the history
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 May 31, 2019
1 parent 411c15f commit 6106c62
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 23 deletions.
12 changes: 1 addition & 11 deletions command/jsonplan/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
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 6106c62

Please sign in to comment.