-
Notifications
You must be signed in to change notification settings - Fork 7
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
Made it possible to parse yaml with null values #3
Conversation
Great catch! I wonder if we should be silently omitting such fields or rather coercing them to empty strings? Given the resource name of |
@anton-dessiatov are you interested in discussing/adjusting PR or should I just merge it and take care of the rest? |
Sorry for the delay. I have just created a quick test with two files: main.tf:
yaml.yml:
My PR indeed fails on this example with Terraform complaining that
It's confusing because the key "empty_key" indeed exists in YAML file. So I agree that we have to represent null values somehow. YAML makes a strict difference between null value ( On the other hand, we don't seem to have a way to represent null in Terraform anyway (and please correct me if I'm wrong here). There is a long relevant story about undefined values here: hashicorp/terraform#5471. The fact that Terraform null values can not be encoded makes it impossible for user to actually distinguish between null and an empty string, which invalidates my argument on losing semantics. But we still could do our best to be strict. I believe a good way to go is to pass Terraform |
Hi. Sorry for late reply. I may change my opinion once I see the behavior but I still think that we should force coerce any "void" value to an empty string. I believe that "explicit is better than implicit" and because data source is named "yaml_map_of_strings" it's better to make sure we have just strings in output. Also, as of now, Terraform's type system is pretty primitive and you cannot mix types in map values. Introducing In term of another aspect of ambiguity you mentioned, we may add an option to control behavior in the face of empty values - whether to skip them or coerce to empty strings. However, if we were to do so I'd err on the side of supplying it a default value to not break backward compatibility. |
Hi there, first off I want to say thanks @ashald for this provider -- it is nice to be able to use yaml files with terraform to share configurations between different tools. Hopefully once terraform 0.12 is out which should support arbitrary nested maps, it will be possible to read in a full yaml file into terraform and use it dynamically, without needing multiple invocations of yaml_list_of_strings and yaml_map_of strings. Anyways, I have run into this crash when using a yaml file with empty values and my vote is to set them to empty strings instead of just dropping them from the returned value entirely. Thanks again! |
…as an empty string
I have added a test and this pull request now interprets YAML nulls (actually reflect.Invalids internally) as empty strings. Also squashed previous commits into one. |
Just back from vacation and I'm 😍. @anton-dessiatov thank you for the contribution! |
Also, added you to CONTRIBUTORS.md - hope you don't mind. 😊 |
Released as a new version https://github.com/ashald/terraform-provider-yaml/releases/tag/v2.0.1 |
Data source "yaml_map_of_strings" with "flatten" enabled used to crash if YAML with empty keys (
key: null
or justkey:
) was passed to it.This PR makes yaml_map_of_strings ignore these empty keys.