-
Notifications
You must be signed in to change notification settings - Fork 96
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
Computed, Optional, RequiresReplace behaviour: state of play #189
Comments
To enumerate additional cases:
I don't think any of these highlight any additional problematic cases (except 12 which must be handled by providers if they do not want to show that difference), but in terms of completely representing our expectations, it might be good to note (or test) all of them. |
Thanks for enumerating all of these permutations for easy scanning! Puts the whole thing into perspective. My sense here though is that the question isn't really answerable, because of the reason you identified: the framework itself can't possibly know what the provider is going to do during the apply phase. "Unknown" is a coarse way for the framework to be honest about that: "the provider hasn't told me what it intends to do, so I don't know" is technically correct (the best kind of correct?! 🙃), but also pretty disruptive in cases where the provider isn't being explicit about what it intends to do. For me then, this seems to come down to a robustness vs. usability tradeoff:
It seems pretty hard to develop a sense for how often provider logic was failing to update computed attributes in the plan before, because we retained the legacy SDK opt-out and so those problems appear only as warnings rather than as explicit errors under the old SDK. I was initially tempted to say that obviously the second option above was better, but I reconsidered after realizing that the legacy SDK opt-out may be giving me a misleading read on the situation. Do you think there's some reasonable way we could survey existing practical providers and see how commonly the existing logic falls foul of the post-apply consistency safety check? That seems like it would help test if "most of the time computed attributes don't change during update" is really true, or if it's just an illusion due to that problem generally turning up only downstream today. If computed attributes often tend to change during an update, then this seems more like necessary complexity to me and thus I'd lean more towards the first option above (which I believe matches the current framework behavior) in the interests of getting quicker feedback when the necessary logic is missing, so we can address it more proactively. Mostly just thinking aloud here... not proposing anything in particular. |
(I suppose there are some possible compromises between those two, such as defaulting to the "robust" option but having a per-attribute declarative way to opt it in to the "usability" option, which I suppose is approximately what #180 was about.) |
I think an important wrinkle to understanding this problem and its impacts is to complicate our understanding of what "computed" means here. It's true that it includes relatively-rarely updated computed-only fields, but it's also true that (I believe) more frequently used patterns are impacted. For example, in any list of nested attributes (in SDKv2, would've been a list with an Elem of schema.Resource) that has any computed attributes, replacing any item in the list triggers this, because the computed attributes change. So, for example, if you have a list of disks and then change one of the disks or the disk gets recreated and gets, e.g., a new ID, you get a plan-didn't-match-apply error unless you explicitly allow that scenario. My expectation is that, in light of that information, the situation is more widespread than we'd anticipate in SDKv2 and provider developers are more likely to run into it. I think my concern here about the possibility of requiring provider developers to explicitly say it's going to happen is that the learning curve for provider development when working with computed attributes then becomes much steeper: we need to introduce the plan modification concept much earlier than we would otherwise need to. |
I believe this is something we can directionally approximate, and am poking at some leads there we can talk about privately to see if we can work with a less theoretical understanding here. |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
As of 4b382e2,
terraform plan
will output the following in its diff for an attribute with these combinations of properties:terraform plan
outputterraform plan
outputProblematic cases are discussed below.
Case 3:
Computed
attribute, null in configIn the framework's initial releases, updating a
Computed
attribute would lead to a "Provider produced inconsistent result after apply" error (see #175), because the framework would return "a" from PlanResourceChange, only to set the value to something else during apply.We changed this behaviour in #176 and instead returned
Unknown
from PlanResourceChange in such cases.Any Unknown value in the plan is represented in the CLI output as "(known after apply)". This gives the user the impression (see #187) that the value is changing, even the provider does not actually change the value.
SDKv2 would return the old state value instead, so no diff would show in the CLI.
In this case, both the old and the new behaviours are potentially problematic, since the user may get a false impression that the value is changing, or a false impression that the value is changing.
Case 4:
Computed
attribute withRequiresReplace
, null in configAs in case 3, the planned value of this attribute is set to Unknown, leading to "(known after apply)" being printed in the CLI.
In addition, including this attribute's path in the
RequiresReplace
field of the PlanResourceChange response triggers Core logic which checks whether the old state value is equal to the provider's planned state. If they are not equal, it marks the resource as requiring replacement and prints# forces replacement
in the CLI. SinceUnknown
does not equal"a"
, the resource is marked as requiring replacement.This leads to problems such as #187. The resource will be destroyed and recreated even though the value of the Computed attribute would not have changed.
Again, it is unclear what the desired CLI output is here, since we cannot assume that the provider either will or will not change the value of the Computed attribute.
Conclusion
The fundamental problem these cases demonstrate is that it is not possible to know the value of a Computed attribute at plan time: it is therefore not possible to know whether a resource whose attribute is marked RequiresReplace needs to be destroyed and recreated.
The text was updated successfully, but these errors were encountered: