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