unmark decoded changes for jsonplan

Marks are not needed when transcoding changes from the internal msgpack
format to json.
This commit is contained in:
James Bardin 2021-05-12 11:10:03 -04:00
parent 213f3391c3
commit 25cebfbd8b
2 changed files with 22 additions and 6 deletions

View File

@ -212,10 +212,15 @@ func (p *plan) marshalResourceChanges(changes *plans.Changes, schemas *terraform
if err != nil { if err != nil {
return err return err
} }
// We drop the marks from the change, as decoding is only an
// intermediate step to re-encode the values as json
changeV.Before, _ = changeV.Before.UnmarkDeep()
changeV.After, _ = changeV.After.UnmarkDeep()
var before, after []byte var before, after []byte
var beforeSensitive, afterSensitive []byte var beforeSensitive, afterSensitive []byte
var afterUnknown cty.Value var afterUnknown cty.Value
if changeV.Before != cty.NilVal { if changeV.Before != cty.NilVal {
before, err = ctyjson.Marshal(changeV.Before, changeV.Before.Type()) before, err = ctyjson.Marshal(changeV.Before, changeV.Before.Type())
if err != nil { if err != nil {
@ -338,6 +343,10 @@ func (p *plan) marshalOutputChanges(changes *plans.Changes) error {
if err != nil { if err != nil {
return err return err
} }
// We drop the marks from the change, as decoding is only an
// intermediate step to re-encode the values as json
changeV.Before, _ = changeV.Before.UnmarkDeep()
changeV.After, _ = changeV.After.UnmarkDeep()
var before, after []byte var before, after []byte
afterUnknown := cty.False afterUnknown := cty.False

View File

@ -60,15 +60,17 @@ func marshalPlannedOutputs(changes *plans.Changes) (map[string]output, error) {
if err != nil { if err != nil {
return ret, err return ret, err
} }
// The values may be marked, but we must rely on the Sensitive flag
// as the decoded value is only an intermediate step in transcoding
// this to a json format.
changeV.After, _ = changeV.After.UnmarkDeep()
if changeV.After != cty.NilVal { if changeV.After != cty.NilVal && changeV.After.IsWhollyKnown() {
if changeV.After.IsWhollyKnown() {
after, err = ctyjson.Marshal(changeV.After, changeV.After.Type()) after, err = ctyjson.Marshal(changeV.After, changeV.After.Type())
if err != nil { if err != nil {
return ret, err return ret, err
} }
} }
}
ret[oc.Addr.OutputValue.Name] = output{ ret[oc.Addr.OutputValue.Name] = output{
Value: json.RawMessage(after), Value: json.RawMessage(after),
@ -193,6 +195,11 @@ func marshalPlanResources(changes *plans.Changes, ris []addrs.AbsResourceInstanc
if err != nil { if err != nil {
return nil, err return nil, err
} }
// The values may be marked, but we must rely on the Sensitive flag
// as the decoded value is only an intermediate step in transcoding
// this to a json format.
changeV.Before, _ = changeV.Before.UnmarkDeep()
changeV.After, _ = changeV.After.UnmarkDeep()
if changeV.After != cty.NilVal { if changeV.After != cty.NilVal {
if changeV.After.IsWhollyKnown() { if changeV.After.IsWhollyKnown() {