terragrunt icon indicating copy to clipboard operation
terragrunt copied to clipboard

Terragrunt fmt fails when common files contain includes

Open TaxBusby opened this issue 2 years ago • 2 comments
trafficstars

Describe the bug Issue is similar to #824 but for the builtin terragrunt fmt command. Terragrunt is trying to parse some files as modules that should only be used as includes in other modules, and the command fails.

When I run terragrunt fmt -recursive -check on the root of my repo, I get:

ERRO[0000] Error: Error in function call
      
ERRO[0000]   on /path/to/repo/terragrunt.hcl line 15, in locals: 
ERRO[0000]   15:   environment_vars = read_terragrunt_config(find_in_parent_folders("env.hcl")) 
ERRO[0000]                                              
ERRO[0000] Call to function "find_in_parent_folders" failed: ParentFileNotFound: Could not find a env.hcl in any of the parent folders of /path/to/repo/terragrunt.hcl. Cause: Traversed all the way to the root..

I have a repo structure like the following:

├── root
├── account-1
│   ├── region-1
│   │   └── terragrunt.hcl
│   ├── region-2
│   │   └── terragrunt.hcl
|   └── env.hcl
└── terragrunt.hcl

And my root terragrunt.hcl contains:

locals {
  # Automatically load environment-level variables
  environment_vars = read_terragrunt_config(find_in_parent_folders("env.hcl"))
}

in order to load some common config files

Expected behavior Terragrunt format should avoid parsing these includes, or provide a workaround to skip a folder or file with includes.

Versions

  • Terragrunt version: Tested 0.36.6 and 0.48.6
  • Terraform version: 1.2.2
  • Environment details (Ubuntu 20.04, Windows 10, etc.): MacOS + Linux

Additional context I'm not super familiar with terragrunt structures. If there's a workaround in how I author this root terragrunt.hcl I'd be happy to apply it, or some way I can get the format command to ignore this root folder. hclfmt works fine and has no issue parsing any of these files.

TaxBusby avatar Aug 08 '23 06:08 TaxBusby

We're having this problem too!

D:\repository\account>terragrunt fmt -check -recursive
time=2023-09-01T13:41:53+02:00 level=error msg=Error reading file at path D:/repository/account/terragrunt.hcl: open D:/repository/account/terragrunt.hcl: Impossibile trovare il file specificato.
time=2023-09-01T13:41:53+02:00 level=error msg=Unable to determine underlying exit code, so Terragrunt will exit with error code 1

GiamPy5 avatar Sep 01 '23 11:09 GiamPy5