sl1pm4t / k2tf

Kubernetes YAML to Terraform HCL converter
Mozilla Public License 2.0
1.17k stars 108 forks source link

Enhancement/question: generic yaml -> hcl2 converter? #74

Open schollii opened 3 years ago

schollii commented 3 years ago

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.

sl1pm4t commented 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.

redeux commented 3 years ago

I believe you can do this with the Terraform yamldecode function.

schollii commented 3 years ago

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.

DanTulovsky commented 3 years ago

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.