From 25cebfbd8be2c43a25dfafdcf882e79b9ccc3d3d Mon Sep 17 00:00:00 2001 From: James Bardin Date: Wed, 12 May 2021 11:10:03 -0400 Subject: [PATCH] unmark decoded changes for jsonplan Marks are not needed when transcoding changes from the internal msgpack format to json. --- command/jsonplan/plan.go | 9 +++++++++ command/jsonplan/values.go | 19 +++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/command/jsonplan/plan.go b/command/jsonplan/plan.go index 1db2067d4..c9ea550fe 100644 --- a/command/jsonplan/plan.go +++ b/command/jsonplan/plan.go @@ -212,10 +212,15 @@ func (p *plan) marshalResourceChanges(changes *plans.Changes, schemas *terraform if err != nil { 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 beforeSensitive, afterSensitive []byte var afterUnknown cty.Value + if changeV.Before != cty.NilVal { before, err = ctyjson.Marshal(changeV.Before, changeV.Before.Type()) if err != nil { @@ -338,6 +343,10 @@ func (p *plan) marshalOutputChanges(changes *plans.Changes) error { if err != nil { 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 afterUnknown := cty.False diff --git a/command/jsonplan/values.go b/command/jsonplan/values.go index 99d26cfde..bf1ee6dc4 100644 --- a/command/jsonplan/values.go +++ b/command/jsonplan/values.go @@ -60,13 +60,15 @@ func marshalPlannedOutputs(changes *plans.Changes) (map[string]output, error) { if err != nil { 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.IsWhollyKnown() { - after, err = ctyjson.Marshal(changeV.After, changeV.After.Type()) - if err != nil { - return ret, err - } + if changeV.After != cty.NilVal && changeV.After.IsWhollyKnown() { + after, err = ctyjson.Marshal(changeV.After, changeV.After.Type()) + if err != nil { + return ret, err } } @@ -193,6 +195,11 @@ func marshalPlanResources(changes *plans.Changes, ris []addrs.AbsResourceInstanc if err != nil { 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.IsWhollyKnown() {