From e29eb78cfddfb1cd7f477457d6aedbcb8286fc4c Mon Sep 17 00:00:00 2001 From: James Bardin Date: Tue, 11 May 2021 17:37:07 -0400 Subject: [PATCH] decode change values with marks Marks stored in a plans.ChangeSrc were not decoded along with the stored values. This was working in many cases by evaluation correctly re-evaluating the marks, but this cannot happen in all cases. --- plans/changes_src.go | 5 +++-- plans/changes_test.go | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 plans/changes_test.go diff --git a/plans/changes_src.go b/plans/changes_src.go index fdc0853cc6..63026e73fc 100644 --- a/plans/changes_src.go +++ b/plans/changes_src.go @@ -200,9 +200,10 @@ func (cs *ChangeSrc) Decode(ty cty.Type) (*Change, error) { return nil, fmt.Errorf("error decoding 'after' value: %s", err) } } + return &Change{ Action: cs.Action, - Before: before, - After: after, + Before: before.MarkWithPaths(cs.BeforeValMarks), + After: after.MarkWithPaths(cs.AfterValMarks), }, nil } diff --git a/plans/changes_test.go b/plans/changes_test.go new file mode 100644 index 0000000000..555a0c7726 --- /dev/null +++ b/plans/changes_test.go @@ -0,0 +1,41 @@ +package plans + +import ( + "fmt" + "testing" + + "github.com/zclconf/go-cty/cty" +) + +func TestChangeEncodeSensitive(t *testing.T) { + testVals := []cty.Value{ + cty.ObjectVal(map[string]cty.Value{ + "ding": cty.StringVal("dong").Mark("sensitive"), + }), + cty.StringVal("bleep").Mark("bloop"), + cty.ListVal([]cty.Value{cty.UnknownVal(cty.String).Mark("sup?")}), + } + + for _, v := range testVals { + t.Run(fmt.Sprintf("%#v", v), func(t *testing.T) { + change := Change{ + Before: cty.NullVal(v.Type()), + After: v, + } + + encoded, err := change.Encode(v.Type()) + if err != nil { + t.Fatal(err) + } + + decoded, err := encoded.Decode(v.Type()) + if err != nil { + t.Fatal(err) + } + + if !v.RawEquals(decoded.After) { + t.Fatalf("%#v != %#v\n", decoded.After, v) + } + }) + } +}