github.com/terramate-io/tf@v0.0.0-20230830114523-fce866b4dfcd/command/jsonformat/differ/sensitive.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: MPL-2.0 3 4 package differ 5 6 import ( 7 "github.com/zclconf/go-cty/cty" 8 9 "github.com/terramate-io/tf/command/jsonformat/computed" 10 "github.com/terramate-io/tf/command/jsonformat/computed/renderers" 11 "github.com/terramate-io/tf/command/jsonformat/structured" 12 "github.com/terramate-io/tf/command/jsonprovider" 13 "github.com/terramate-io/tf/plans" 14 ) 15 16 type CreateSensitiveRenderer func(computed.Diff, bool, bool) computed.DiffRenderer 17 18 func checkForSensitiveType(change structured.Change, ctype cty.Type) (computed.Diff, bool) { 19 return change.CheckForSensitive( 20 func(value structured.Change) computed.Diff { 21 return ComputeDiffForType(value, ctype) 22 }, func(inner computed.Diff, beforeSensitive, afterSensitive bool, action plans.Action) computed.Diff { 23 return computed.NewDiff(renderers.Sensitive(inner, beforeSensitive, afterSensitive), action, change.ReplacePaths.Matches()) 24 }, 25 ) 26 } 27 28 func checkForSensitiveNestedAttribute(change structured.Change, attribute *jsonprovider.NestedType) (computed.Diff, bool) { 29 return change.CheckForSensitive( 30 func(value structured.Change) computed.Diff { 31 return computeDiffForNestedAttribute(value, attribute) 32 }, func(inner computed.Diff, beforeSensitive, afterSensitive bool, action plans.Action) computed.Diff { 33 return computed.NewDiff(renderers.Sensitive(inner, beforeSensitive, afterSensitive), action, change.ReplacePaths.Matches()) 34 }, 35 ) 36 } 37 38 func checkForSensitiveBlock(change structured.Change, block *jsonprovider.Block) (computed.Diff, bool) { 39 return change.CheckForSensitive( 40 func(value structured.Change) computed.Diff { 41 return ComputeDiffForBlock(value, block) 42 }, func(inner computed.Diff, beforeSensitive, afterSensitive bool, action plans.Action) computed.Diff { 43 return computed.NewDiff(renderers.SensitiveBlock(inner, beforeSensitive, afterSensitive), action, change.ReplacePaths.Matches()) 44 }, 45 ) 46 }