-
Notifications
You must be signed in to change notification settings - Fork 561
Optional strings should default to null
not ""
#768
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
Comments
Was raised here too, but not addressed - the author decided to close the ticket :( |
Hey @khos2ow , sorry for the ping. This is still relevant for my use-case. Could you please explain the logic behind |
In Terraform/OpenTofu, In Go, the language is strongly typed, meaning that great lengths are taken to avoid Keeping I haven't looked closely enough at the internals of this project (yet) to get a sense of how complex it might be to add support for this, but I've used the hclparse package to do some custom HCL parsing and generation, and it's not for the faint of heart. You are perfectly correct that Terraform interprets the code this way, but a separate tool (e.g., this one) would need to do a non-trivial amount of work to interpret the same value the same way. My speculation is that, up to this point, the "juice hasn't been worth the squeeze." Anyway, that's the explanation for how it works in Go, and my unsurprise at |
Thanks for the very elaborate explanation! TIL :) I went in the code and tried to unwrap if there's any special magic done for typing and stumbled upon this: https://github.com/terraform-docs/terraform-docs/blob/master/format/tfvars_hcl.go#L49-L54 If I read it correctly - this condition is specifically handling the case and changing I'll try to test this w/o the condition to see if it works ok. UPD: This is it! Worked like a charm. I'll be making a PR to address that, though still not clear what was the original intent behind |
Fixes: terraform-docs#609, related to terraform-docs#768 Signed-off-by: Oleksandr Simkin <[email protected]>
Describe the bug
When I ran
terraform-docs tfvars hcl .
, optional strings with no default value were represented as""
.I did a bit of reading on Type Constraints on Optional Object Type Attributes. Long story short is, a
string
type with no default value evaluates totostring(null)
, not""
.How can we reproduce it?
cd
into theexamples/terraform/aws
directory.terraform-docs tfvars hcl .
Environment information
The text was updated successfully, but these errors were encountered: