2023-05-02 11:33:06 -04:00
|
|
|
// Copyright IBM Corp. 2014, 2026
|
2023-08-10 18:43:27 -04:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-05-02 11:33:06 -04:00
|
|
|
|
2023-01-09 05:40:47 -05:00
|
|
|
package differ
|
|
|
|
|
|
2023-01-09 14:38:25 -05:00
|
|
|
import (
|
|
|
|
|
"github.com/zclconf/go-cty/cty"
|
2023-01-09 05:40:47 -05:00
|
|
|
|
2023-01-10 11:24:48 -05:00
|
|
|
"github.com/hashicorp/terraform/internal/command/jsonformat/computed"
|
|
|
|
|
"github.com/hashicorp/terraform/internal/command/jsonformat/computed/renderers"
|
2023-04-21 03:51:55 -04:00
|
|
|
"github.com/hashicorp/terraform/internal/command/jsonformat/structured"
|
2023-01-09 14:38:25 -05:00
|
|
|
"github.com/hashicorp/terraform/internal/command/jsonprovider"
|
2023-01-12 11:59:07 -05:00
|
|
|
"github.com/hashicorp/terraform/internal/plans"
|
2023-01-09 14:38:25 -05:00
|
|
|
)
|
|
|
|
|
|
2023-01-11 03:04:26 -05:00
|
|
|
type CreateSensitiveRenderer func(computed.Diff, bool, bool) computed.DiffRenderer
|
|
|
|
|
|
2023-04-21 03:51:55 -04:00
|
|
|
func checkForSensitiveType(change structured.Change, ctype cty.Type) (computed.Diff, bool) {
|
2023-04-24 04:28:21 -04:00
|
|
|
return change.CheckForSensitive(
|
|
|
|
|
func(value structured.Change) computed.Diff {
|
|
|
|
|
return ComputeDiffForType(value, ctype)
|
|
|
|
|
}, func(inner computed.Diff, beforeSensitive, afterSensitive bool, action plans.Action) computed.Diff {
|
|
|
|
|
return computed.NewDiff(renderers.Sensitive(inner, beforeSensitive, afterSensitive), action, change.ReplacePaths.Matches())
|
|
|
|
|
},
|
|
|
|
|
)
|
2023-01-09 14:38:25 -05:00
|
|
|
}
|
|
|
|
|
|
2023-04-21 03:51:55 -04:00
|
|
|
func checkForSensitiveNestedAttribute(change structured.Change, attribute *jsonprovider.NestedType) (computed.Diff, bool) {
|
2023-04-24 04:28:21 -04:00
|
|
|
return change.CheckForSensitive(
|
|
|
|
|
func(value structured.Change) computed.Diff {
|
|
|
|
|
return computeDiffForNestedAttribute(value, attribute)
|
|
|
|
|
}, func(inner computed.Diff, beforeSensitive, afterSensitive bool, action plans.Action) computed.Diff {
|
|
|
|
|
return computed.NewDiff(renderers.Sensitive(inner, beforeSensitive, afterSensitive), action, change.ReplacePaths.Matches())
|
|
|
|
|
},
|
|
|
|
|
)
|
2023-01-09 14:38:25 -05:00
|
|
|
}
|
|
|
|
|
|
2023-04-21 03:51:55 -04:00
|
|
|
func checkForSensitiveBlock(change structured.Change, block *jsonprovider.Block) (computed.Diff, bool) {
|
2023-04-24 04:28:21 -04:00
|
|
|
return change.CheckForSensitive(
|
|
|
|
|
func(value structured.Change) computed.Diff {
|
|
|
|
|
return ComputeDiffForBlock(value, block)
|
|
|
|
|
}, func(inner computed.Diff, beforeSensitive, afterSensitive bool, action plans.Action) computed.Diff {
|
|
|
|
|
return computed.NewDiff(renderers.SensitiveBlock(inner, beforeSensitive, afterSensitive), action, change.ReplacePaths.Matches())
|
|
|
|
|
},
|
|
|
|
|
)
|
2023-01-09 05:40:47 -05:00
|
|
|
}
|