Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DiffSuppressFunc alternative? #1030

Open
amalavet opened this issue Aug 26, 2024 · 1 comment
Open

DiffSuppressFunc alternative? #1030

amalavet opened this issue Aug 26, 2024 · 1 comment
Labels
enhancement New feature or request waiting-response Issues or pull requests waiting for an external response

Comments

@amalavet
Copy link

amalavet commented Aug 26, 2024

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

@amalavet amalavet added the enhancement New feature or request label Aug 26, 2024
@austinvalle
Copy link
Member

Hey there @amalavet 👋🏻!

The valid use-cases of DiffSuppressFunc were replaced by framework with custom type semantic equality, although I believe what you're describing would be considered invalid to Terraform from a data consistency perspective. The general rules for managed resource plan/apply are fully described here: https://github.com/hashicorp/terraform/blob/main/docs/resource-instance-change-lifecycle.md.

For apply, we'd end up breaking this rule:

Any attribute that had a known value in the Final Planned State must have an identical value in the new state.

If we plan a suppressed/different value then it is required by the Terraform provider to return this exact value in state as well.

If the attribute you're describing is a configuration value, you also are not able to plan a value that does not exactly match configuration or the prior state value:

Any attribute that was non-null in the configuration must either preserve the exact configuration value or return the corresponding attribute value from the prior state.


DiffSuppressFunc is able to do what you've described because data consistency rules are not applied to SDKv2 for compatibility reasons: https://developer.hashicorp.com/terraform/plugin/sdkv2/resources/data-consistency-errors

@austinvalle austinvalle added the waiting-response Issues or pull requests waiting for an external response label Aug 30, 2024
@github-actions github-actions bot removed the waiting-response Issues or pull requests waiting for an external response label Aug 30, 2024
@austinvalle austinvalle added the waiting-response Issues or pull requests waiting for an external response label Aug 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request waiting-response Issues or pull requests waiting for an external response
Projects
None yet
Development

No branches or pull requests

2 participants