terraform-switcher icon indicating copy to clipboard operation
terraform-switcher copied to clipboard

feat: use terragrunt parser to parse terragrunt.hcl

Open marcoreni opened this issue 2 years ago • 3 comments

Fixes #259 .

This PR introduces the Terragrunt parser to handle terragrunt.hcl parsing, so that include blocks can be read and more complex logics of constraints can be handled (for example, having the constraint inside a parent file).

Pros:

  • Uses Terragrunt logics, that is thoroughly tested on the terragrunt repo.
  • The same mechanism can be added to tgswitch with minimal effort.

Cons:

  • Since Terragrunt does not expose APIs, using it requires lots of libraries (+20MB in my sample compiled build) and requires logrus to be initialized to avoid crash.

LMKWYT

marcoreni avatar Jul 22 '22 15:07 marcoreni

Hey 👋 I have the same use case with hierarchical terraform/terragrunt constraints definition.

terragrunt.hcl     # <= terraform_version_constraint = "1.1.6"
test
  component
    terragrunt.hcl # <= implicit include of the root terragrunt.hcl config, no explicit terraform_version_constraint definition
prod
  component
    terragrunt.hcl

As far as tfswitch already supports current terragrunt.hcl parsing I think it's reasonable to extend it further.

Another option could be checking .tfswitchrc file presence from the current folder to root one, a bottom-up search through a hierarchy.

.tfswitchrc     # <= 1.1.6
test
  component 
                # <= Switch to default 1.1.6
prod
  component
    .tfswitchrc # <= Switch to override 1.1.7

Tensho avatar Jul 25 '22 09:07 Tensho

@Tensho that is another possibility, yes. I went this way because by using the hcl I would need to declare the constraint once and I would be able to delete the .tfswitchrc files entirely

marcoreni avatar Sep 01 '22 11:09 marcoreni

@marcoreni Could you rebase and update this PR to the latest terragrunt version? There seems to be a lot of changes since you opened that PR. Also it would be good to have a test case for that.

MatrixCrawler avatar Apr 05 '24 18:04 MatrixCrawler