How to handle DiffSuppressFunc on plugin framework?

I have a DiffSuppressFunc, which sanitizes the string and removes the extra spaces or new lines on the string.
Basically the existing functionality works, like user provides a string as “abc \n”, “abc” get saved to state file and we suppress this diff.

Now when moving to plugin framework, I am not able to get rid of this.

I have created a ModifyPlan( function for this

like this

		configKey := plan.Key.ValueString()
		// State value is already normalized from the API
		stateKey := state.Key.ValueString()

		// If the normalized config matches the state, use the state value
		if suppressKeyDiff(stateKey, configKey) {
			plan.Key = state.Key
			resp.Plan.Set(ctx, plan)
		}

This isn’t working, on create, I am getting

Error: Provider produced inconsistent result after apply
produced an unexpected new value: .key: was cty.StringVal("abc\n"), but now cty.StringVal("abc").
│ 
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.

@apparentlymart @jbardin is this achievable using the plugin framework ?

@ramuklawjju, The framework refers to this type of normalization as “semantic equality”.

It sounds like you are missing the third check described there in the docs, you must check the new value crated during apply, and retain the configuration value if there is no semantic difference.

1 Like