Automatically preserve functionally-equivalent configuration values during refresh #19
Labels
enhancement
New feature or request
terraform-plugin-framework
Resolved in terraform-plugin-framework
Milestone
In Terraform's model, there are conceptually two different ways to interpret a difference between the configuration and a state. If we assume that it's the state that's changed while the config remains the same, those cases are:
(If it's the configuration that changed rather than the state then the exact definitions of the above would be different, but the same distinction still exists.)
In the original SDK (
helper/schema
) we modeled this difference usingDiffSuppressFunc
on a per-attribute basis, allowing the provider to decide for each given change whether it is "Drift" (returnfalse
) or "Normalization" (returntrue
).Unfortunately,
DiffSuppressFunc
is considered only during planning, which doesn't cover the common case where theRead
function updates the state to match the value returned by the remote API, thus making a normalization change effective in the state. On a subsequent plan, that attribute itself may not show up as having a diff (becauseDiffSuppressFunc
hopefully returnedtrue
) but any other resource whose configuration depends on that value will now show a diff, because that downstream attribute may not even belong to the same provider and thus can't possibly know the logic for deciding Drift vs. Normalization in the general case.Under the general theme of having the SDK do "the right thing" by default, it'd be nice if the SDK would apply
DiffSuppressFunc
(or whatever similar features evolve from it) also to the result ofRead
, so if the provider sets a value that is different only in the normalization sense, the SDK would discard that new value and retain the original value as the user wrote it.The idea that the configuration takes priority in the case of any disagreement is a fundamental assumption in Terraform Core because without it interpolation cannot function reliably: any value derived from that result could otherwise potentially change in response to normalization, causing apply failures or diffs that take one or more additional runs to converge. This is one reason why we implemented
DiffSuppressFunc
even though similar use-cases were already covered byStateFunc
.(From a more subjective standpoint, I also think it's the best user experience: if I write
"Foo"
in the configuration and I interpolate that value somewhere else, it'd be pretty surprising to see that evaluate as"foo"
.)The text was updated successfully, but these errors were encountered: