Open schollii opened 3 years ago
Hi @schollii - at the moment the tool doesn't really read the YAML directly, it uses Kubernetes libraries to parse the YAML into Kubernetes resource objects, and then converts these to HCL. So, supporting YAML to HCL2 would possibly be a bigger change than it might seem. I like the idea though, so I'll keep it in mind if I come back to doing any significant changes to this tool.
I believe you can do this with the Terraform yamldecode
function.
The disadvantage of yamldecode (which is very useful for some tasks) is that terraform cannot validate your code. Eg if I have a config.yaml that I use instead of terraform.tfvars, code completion is not available on the values in config.yaml. Luckily terraform can load tfvars in json format which is easy to generate from Python.
I believe that https://github.com/jrhouston/tfk8s will do what you want. Caveat is it produces output that works with the https://github.com/hashicorp/terraform-provider-kubernetes-alpha provider.
Any chance k2tf could just be a generic yaml to hcl2 converter? Perhaps a mode flag which causes it to load yaml and just spit out the equivalent HCL2 syntax to stdout.