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

Optional and Computed fields cannot be updated to an empty string #173

Closed
kayrus opened this issue Aug 27, 2019 · 6 comments
Closed

Optional and Computed fields cannot be updated to an empty string #173

kayrus opened this issue Aug 27, 2019 · 6 comments

Comments

@kayrus
Copy link

kayrus commented Aug 27, 2019

Terraform Version

Terraform v0.12.7
+ custom provider, which uses the v0.12.7 SDK

Terraform Configuration Files

                        "optional_computed_string": {
                                Type:     schema.TypeString,
                                Optional: true,
                                Computed: true,
                        },
                        "optional_computed_int": {
                                Type:     schema.TypeInt,
                                Optional: true,
                                Computed: true,
                        },
resource "some_resource" "foo" {
  optional_computed_string = ""
  optional_computed_int = 0
}

Debug Output

Crash Output

Expected Behavior

I expect that optional computed field empty string value will be detected as desirable and terraform will try to update this string, as it is done with integer variable being explicitly set to 0.

Actual Behavior

Setting the optional computed field to an empty string is not reflected in a change and terraform doesn't update the computed field to an empty string.

Steps to Reproduce

Additional Context

References

Probably related to hashicorp/terraform#21760

@teamterraform
Copy link
Contributor

Hi @kayrus!

We marked this as an enhancement because the SDK is currently working as designed (it considers empty string equivalent to not being set at all because Terraform 0.11 and earlier do not have null).

However, this is good feedback that will inform future changes to the design of the SDK as we prepare for adopting new Terraform 0.12 features, like the new explicit null. Thanks for creating it!

@kayrus
Copy link
Author

kayrus commented Aug 27, 2019

I just wonder why zero int is handled correctly. Haven't dig deep into the code.

@hashibot hashibot transferred this issue from hashicorp/terraform Sep 26, 2019
@kayrus
Copy link
Author

kayrus commented Oct 2, 2019

Any news on this issue?

@kayrus
Copy link
Author

kayrus commented Nov 26, 2019

@radeksimko @apparentlymart any news on this issue?

@radeksimko
Copy link
Member

Hi @kayrus
Thank you for the report. As it was already mentioned above this is an effect of the way Terraform 0.11 and earlier versions handled types. While 0.12 has first-class support for null, the SDK is still retaining backwards compatibility (which means most providers could be just recompiled without further changes to become 0.12 compatible), hence the SDK and providers still suffer from the same type-related shortcomings, despite being driven by 0.12 with the new type system.

Supporting 0.12 types (which includes null) in SDK is one of our current priorities. We are practically sure though that supporting these in a provider will require deprecation of <0.12 from provider's perspective as only 0.12 uses the new protocol that allows us to carry all the important details about types.

The best you can do in the meantime is to read this blogpost, share it and encourage everyone to upgrade to 0.12.

I'm going to close this as duplicate of #102 since it covers all types and it will allow us to keep discussion in one place.

@ghost
Copy link

ghost commented Mar 28, 2020

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.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Mar 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants