-
Notifications
You must be signed in to change notification settings - Fork 236
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
Optional+Computed attribute of type string can't be force zeroed #282
Comments
Hi @magodo I just relabelled the issue as the SDK/Terraform does what it was designed for, although maybe not what you expect. The borders between bug and enhancement are a bit blurry here, but I will do my best to explain my reasoning below. As This is all aligned with design decisions of the SDK, but may not be aligned with design of some APIs. I vaguely remember AWS land has resources/APIs where such field is expected to be zero-ed and not be sent to the API in following requests, but I can't remember exact examples. Generally it is sensible for us to change the SDK and alter the design to reflect behaviour of APIs in the wild. To do that though it would be incredibly helpful to have more concrete examples, ideally with links to API docs. We'd like to know why do we need to zero the field and what would happen if it doesn't get zero-ed and also what value do we expect to get from the API after we wipe it and whether it's the same as default value set after initial creation. i.e. does the field default to a static value (in which case it probably shouldn't be |
Hi @radeksimko I have an live example in azure land, in resource virtual network, there is a property named The expected behavior I expected is that, if the property is explicitly set to any string (incl. empty string), it should be reflected in diff. Otherwise, if it was totally omitted, then respect the |
There is more generic problem related to the fact that the SDK or Terraform doesn't differentiate between empty string and This issue is tracked in #102 While resolving that will make it behave as you described, I still think there's more work to do. I suspect If we had just single way of defining subnets - e.g. deprecated
I'm hoping we could address this by somehow allowing providers to couple the schema and lifecycle of certain resources (which helps reusability) and make Terraform understand which one is the point of truth without having to mark fields The two issues above are the ones I'd suggest following, but I will keep this one open for now as I imagine there may be some other examples which may require different solution. |
@radeksimko - this has come up yet again in AzureRM (actually multiple times the last couple weeks) for a property where the API sets a default if not specified (that changes based on a few factors so a default value wouldn't work, and if we did add one it would depend on multiple properties excluding a DefaultFunc), the user has then set it to something different, and then wants to clear the property by setting it to empty and there is currently no way to enable this senario with the current SDK/terraform behaviour. Has there be any further discussion/progress on this issue and will it be address in v2 of the sdk? There are multiple situations in AzureRM where we need to use optional+computed and there is no alternative. |
I don't think for backwards compatibility we will be able to do this in the existing SDK methods, but I do think we can probably introduce some new methods or functionality to achieve this, potentially as part of implementing #261 |
…4] (#78) [sc-111204] When neither interval or storage_policy is specified, a server-side default is returned. This causes a diff-after-apply, so mark the field as computed. Note: When using a computed field, if the user sets an explicitly value, say `interval=60s`, and then removes that field, Terraform cannot differentiate whether the value in the state is a server-side default or previously set, and will continue to use the existing value as-is. See hashicorp/terraform-plugin-sdk#282
SDK version
Relevant provider source code
I just write a dummy provider to better illustrate my question.
Below code is the schema definition, there defined 3 different attributes:
Terraform Configuration Files
Steps to Reproduce
terraform apply
with the config i attached aboveterraform plan
Expected Behavior
Actual Behavior
The
name
attribute doesn't honour the force zero operartion.The text was updated successfully, but these errors were encountered: