diff --git a/command/format/diff.go b/command/format/diff.go index 4a14bf1191..53e7fd68e3 100644 --- a/command/format/diff.go +++ b/command/format/diff.go @@ -790,6 +790,11 @@ func (p *blockBodyDiffPrinter) writeValueDiff(old, new cty.Value, indent int, pa unmarkedNew, _ = new.UnmarkDeep() } switch { + case ty == cty.Bool || ty == cty.Number: + if old.ContainsMarked() || new.ContainsMarked() { + p.buf.WriteString("(sensitive)") + return + } case ty == cty.String: // We have special behavior for both multi-line strings in general // and for strings that can parse as JSON. For the JSON handling diff --git a/command/format/diff_test.go b/command/format/diff_test.go index 856dd25d22..1d0a2fedba 100644 --- a/command/format/diff_test.go +++ b/command/format/diff_test.go @@ -3652,36 +3652,57 @@ func TestResourceChange_sensitiveVariable(t *testing.T) { } `, }, - "in-place update - before sensitive": { + "in-place update - before sensitive, primitive types": { Action: plans.Update, Mode: addrs.ManagedResourceMode, Before: cty.ObjectVal(map[string]cty.Value{ - "id": cty.StringVal("i-02ae66f368e8518a9"), - "ami": cty.StringVal("ami-BEFORE"), + "id": cty.StringVal("i-02ae66f368e8518a9"), + "ami": cty.StringVal("ami-BEFORE"), + "special": cty.BoolVal(true), + "some_number": cty.NumberIntVal(1), }), After: cty.ObjectVal(map[string]cty.Value{ - "id": cty.StringVal("i-02ae66f368e8518a9"), - "ami": cty.StringVal("ami-AFTER"), + "id": cty.StringVal("i-02ae66f368e8518a9"), + "ami": cty.StringVal("ami-AFTER"), + "special": cty.BoolVal(false), + "some_number": cty.NumberIntVal(2), }), BeforeValMarks: []cty.PathValueMarks{ { Path: cty.Path{cty.GetAttrStep{Name: "ami"}}, Marks: cty.NewValueMarks("sensitive"), - }}, + }, + { + Path: cty.Path{cty.GetAttrStep{Name: "special"}}, + Marks: cty.NewValueMarks("sensitive"), + }, + { + Path: cty.Path{cty.GetAttrStep{Name: "some_number"}}, + Marks: cty.NewValueMarks("sensitive"), + }, + }, RequiredReplace: cty.NewPathSet(), Tainted: false, Schema: &configschema.Block{ Attributes: map[string]*configschema.Attribute{ - "id": {Type: cty.String, Optional: true, Computed: true}, - "ami": {Type: cty.String, Optional: true}, + "id": {Type: cty.String, Optional: true, Computed: true}, + "ami": {Type: cty.String, Optional: true}, + "special": {Type: cty.Bool, Optional: true}, + "some_number": {Type: cty.Number, Optional: true}, }, }, ExpectedOutput: ` # test_instance.example will be updated in-place ~ resource "test_instance" "example" { # Warning: this attribute value will no longer be marked as sensitive # after applying this change - ~ ami = (sensitive) - id = "i-02ae66f368e8518a9" + ~ ami = (sensitive) + id = "i-02ae66f368e8518a9" + # Warning: this attribute value will no longer be marked as sensitive + # after applying this change + ~ some_number = (sensitive) + # Warning: this attribute value will no longer be marked as sensitive + # after applying this change + ~ special = (sensitive) } `, },