gruntwork-io / terragrunt

Terragrunt is a flexible orchestration tool that allows Infrastructure as Code written in OpenTofu/Terraform to scale.
https://terragrunt.gruntwork.io/
MIT License
7.77k stars 959 forks source link

terragrunt.hcl.json ? #846

Closed maver1ck closed 4 years ago

maver1ck commented 4 years ago

Terraform (and HCL parser) support json input file. Is it possible to use json as input to terragrunt ?

https://www.terraform.io/docs/configuration/syntax-json.html

brikis98 commented 4 years ago

Not currently supported. What's the use case?

maver1ck commented 4 years ago

Automatic generation of hcl files by python script. I prefer json dump than custom jinja templates.

brikis98 commented 4 years ago

Gotcha. I'd be open to a PR for this if it doesn't blow up the complexity of config parsing.

jakauppila commented 4 years ago

I'd be interested in this as well as we may be looking at automating the creation of the terragrunt.hcl configuration for a large number of systems.

After a little poking around, it looks like it might be a matter of adding some parsing of the Terragrunt configuration extension and utilizing ParseJSON from hashicorp/hcl2 https://github.com/hashicorp/hcl2/blob/master/hclparse/parser.go#L74 at https://github.com/gruntwork-io/terragrunt/blob/master/config/config.go#L296 to read in the configuration ?

Would that be the right direction or is there more to consider?

brikis98 commented 4 years ago

Possibly! ParseJSON returns an *hcl.File, so assuming it's the same format we'd get from the HCL parser, then that might work...

jakauppila commented 4 years ago

Threw together a super quick test at https://github.com/jakauppila/terragrunt/commit/b81197805401f2f2d8cc8ed7535af339edea7c0d and appears to be working fine.

How extensive should the JSON config tests be? Should they just mirror all of the HCL config tests?

brikis98 commented 4 years ago

Nice! I don't think we need to mirror 100% of the HCL tests, but enough that the major cases are tested: minimal config, full config, config with lots of nesting, any potential data type conversion issues, etc.