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.
This commit is contained in:
parent
ebc2e5fb56
commit
65fc037ecb
|
@ -210,21 +210,7 @@ func (p *plan) marshalResourceChanges(changes *plans.Changes, schemas *terraform
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
afterUnknown, _ = cty.Transform(changeV.After, func(path cty.Path, val cty.Value) (cty.Value, error) {
|
afterUnknown = cty.EmptyObjectVal
|
||||||
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
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
filteredAfter := omitUnknowns(changeV.After)
|
filteredAfter := omitUnknowns(changeV.After)
|
||||||
if filteredAfter.IsNull() {
|
if filteredAfter.IsNull() {
|
||||||
|
|
|
@ -173,7 +173,7 @@ func TestMarshalPlanResources(t *testing.T) {
|
||||||
Want []resource
|
Want []resource
|
||||||
Err bool
|
Err bool
|
||||||
}{
|
}{
|
||||||
"create with unkonwns": {
|
"create with unknowns": {
|
||||||
Action: plans.Create,
|
Action: plans.Create,
|
||||||
Before: cty.NullVal(cty.EmptyObject),
|
Before: cty.NullVal(cty.EmptyObject),
|
||||||
After: cty.ObjectVal(map[string]cty.Value{
|
After: cty.ObjectVal(map[string]cty.Value{
|
||||||
|
|
|
@ -2,7 +2,6 @@ package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -221,7 +220,6 @@ func TestShow_json_output(t *testing.T) {
|
||||||
json.Unmarshal([]byte(byteValue), &want)
|
json.Unmarshal([]byte(byteValue), &want)
|
||||||
|
|
||||||
if !cmp.Equal(got, want) {
|
if !cmp.Equal(got, want) {
|
||||||
fmt.Println(ui.OutputWriter.String())
|
|
||||||
t.Fatalf("wrong result:\n %v\n", cmp.Diff(got, want))
|
t.Fatalf("wrong result:\n %v\n", cmp.Diff(got, want))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,10 +48,7 @@
|
||||||
"ami": "bar",
|
"ami": "bar",
|
||||||
"id": "placeholder"
|
"id": "placeholder"
|
||||||
},
|
},
|
||||||
"after_unknown": {
|
"after_unknown": {}
|
||||||
"ami": false,
|
|
||||||
"id": false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -69,7 +66,7 @@
|
||||||
"id": "placeholder"
|
"id": "placeholder"
|
||||||
},
|
},
|
||||||
"after": null,
|
"after": null,
|
||||||
"after_unknown": false
|
"after_unknown": {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
|
@ -48,10 +48,7 @@
|
||||||
"ami": "bar",
|
"ami": "bar",
|
||||||
"id": "placeholder"
|
"id": "placeholder"
|
||||||
},
|
},
|
||||||
"after_unknown": {
|
"after_unknown": {}
|
||||||
"ami": false,
|
|
||||||
"id": false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in New Issue