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

GetOk returning exists=false for zero values #4936

Closed
Carles-Figuerola opened this issue Feb 1, 2016 · 3 comments
Closed

GetOk returning exists=false for zero values #4936

Carles-Figuerola opened this issue Feb 1, 2016 · 3 comments

Comments

@Carles-Figuerola
Copy link

When a boolean is set to false, the GetOk helper will unset the exists return value because it assumes a zero value is an unexpected return value.

resource "resource" "foo" {
    bar = false
}
val, ok := d.GetOk("bar"); ok {
    log.Printf("%v, %v", val.(bool), ok)
}

Will print false, false, whereas I would expect it to be false, true

I would expect that values of the int or bool type, would be set by the user to 0 or false as a valid value. Could this behaviour be changed?

@Carles-Figuerola Carles-Figuerola changed the title GetOk working as Get for boolean keys GetOk returning exists=false for zero values Feb 1, 2016
@phinze
Copy link
Contributor

phinze commented Mar 17, 2016

Hi @Carles-Figuerola - I agree this is a bit confusing. It's due to some history around GetOk that I just typed up over here.

We're going to solve this by introducing a proper concept for providers to check whether a given key is set in config or not, and #5694 is going to track that work. So I'll close this issue so we can consolidate our efforts there. Feel free to follow up if you have further questions on this! 👍

@phinze phinze closed this as completed Mar 17, 2016
@Carles-Figuerola
Copy link
Author

Yes, that's exactly it. Thank you very much!

@ghost
Copy link

ghost commented Apr 27, 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 Apr 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants