terraform-plugin-framework icon indicating copy to clipboard operation
terraform-plugin-framework copied to clipboard

DiffSuppressFunc alternative?

Open amalavet opened this issue 6 months ago • 1 comments

Module version

v1.11.0

Use-cases

To keep our plans less verbose, we'd like to be able to obscure/shorten the diff for some of our attributes on our resources.

Attempted Solutions

  1. Setting sensitive obscures the diff, but we want to obscure non-sensitive fields as well
  2. I have attempted to use a plan modifier, but this impacts the value that gets applied to the state as well.
"my_field": schema.StringAttribute{
	...
        Sensitive: true,
},
type suppressFieldValue struct{}

func (m suppressFieldValue) Description(_ context.Context) string {
	return "Suppresses the value within the plan"
}

func (m suppressFieldValue) MarkdownDescription(_ context.Context) string {
	return "Suppresses the value within the plan"
}

func (m suppressFieldValue) PlanModifyString(
	_ context.Context,
	req planmodifier.StringRequest,
	resp *planmodifier.StringResponse,
) {
	resp.PlanValue = types.StringValue("<<SUPPRESSED>>")
}

Proposal

We could have an optional value that, if set, overrides the diff of the attribute within the plan?

... 
func (m suppressFieldValue) PlanModifyString(
	_ context.Context,
	req planmodifier.StringRequest,
	resp *planmodifier.StringResponse,
) {
	resp.PlanDiffValue = types.StringValue("<<SUPPRESSED>>")
}

or just do something like: DiffSuppressFunc from sdkv2

References

  • https://github.com/hashicorp/terraform-plugin-framework/issues/859
  • https://discuss.hashicorp.com/t/diffsuppressfunc-alternative-in-terraform-framework/52578/5
  • https://developer.hashicorp.com/terraform/plugin/framework/resources/plan-modification#creating-attribute-plan-modifiers
  • https://developer.hashicorp.com/terraform/plugin/sdkv2/schemas/schema-behaviors#diffsuppressfunc

amalavet avatar Aug 26 '24 20:08 amalavet