terraform-cdk
terraform-cdk copied to clipboard
[Python] `cdktf synh --hcl` produces unnecessary quotes and bad syntax
Expected Behavior
locals { x = "x" y = local.x }
Actual Behavior
locals { x = "x" y = "${local.x}" }
Steps to Reproduce
- Declare some local variables
x = TerraformLocal(self, "x", "x")
y = TerraformLocal(self, "y", x.as_string)
-
Run
cdktf synth --hcl -
Check
cdktf.out
Versions
cdktf debug language: python cdktf-cli: 0.20.4 node: v21.5.0 cdktf: 0.20.4 constructs: 10.3.0 jsii: 1.94.0 terraform: 1.7.2 arch: x64 os: linux 5.10.102.1-microsoft-standard-WSL2 python: Python 3.8.10 pip: pip 24.0 from /home/andylai/.local/lib/python3.8/site-packages/pip (python 3.8) pipenv: pipenv, version 2023.11.17 providers aws@~> 4.63 (LOCAL) terraform provider version: 4.67.0 cdktf-cdktf-provider-aws (PREBUILT) terraform provider version: 5.39.0 prebuilt provider version: 19.8.0 cdktf version: ^0.20.0
Providers
│ Provider Name │ Provider Version │ CDKTF │ Constraint │ Package Name │ Package Version │ ├───────────────┼──────────────────┼─────────┼────────────┼──────────────────────────┼─────────────────┤ │ aws │ 4.67.0 │ │ ~> 4.63 │ │ │ ├───────────────┼──────────────────┼─────────┼────────────┼──────────────────────────┼─────────────────┤ │ aws │ 5.39.0 │ ^0.20.0 │ │ cdktf-cdktf-provider-aws │ 19.8.0 │
Gist
No response
Possible Solutions
No response
Workarounds
Hardcode the values
Anything Else?
This behaviour causes issues with the terraform linters which are blocking PRs.
References
No response
Help Wanted
- [ ] I'm interested in contributing a fix myself
Community Note
- Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
- Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
- If you are interested in working on this issue or have submitted a pull request, please leave a comment
Hi there, Could you specify the "bad syntax" part? Wrapping this property in quotes is not necessary, but I checked the snippet and it's definitely valid.
It is still allowed for now, but it is not advised by mainstream conventions. Notably, quoted references are officially considered deprecated by Hashicorp a few years ago. And as a result, it wouldn't be ideal to continue to use such a syntax: https://discuss.hashicorp.com/t/terraform-0-12-14-released/3898
This also runs the risk of generated TF to be flagged by TF style checkers without additional intervention, which happens in my case.
Here's a similar ticket cut in another project: https://github.com/terraform-google-modules/terraform-google-kubernetes-engine/issues/373