terragrunt icon indicating copy to clipboard operation
terragrunt copied to clipboard

`run_cmd` is executed twice

Open adovy opened this issue 3 years ago • 2 comments

it seems that run_cmd is executed twice.

terragrunt.hcl:

include {
  path = find_in_parent_folders("terragrunt.hcl")
}

locals {
  common_vars = read_terragrunt_config(find_in_parent_folders("terragrunt.hcl"))
}

Parent terragrunt.hcl:

locals {
  test = run_cmd("python", "get_bucket.py", "production")
}

Output:

$ terragrunt init
my-production-backend-bucket
my-production-backend-bucket
ERRO[0000] Did not find any Terraform files (*.tf) in /Documents/terragrunt/test 
ERRO[0000] Unable to determine underlying exit code, so Terragrunt will exit with error code 1 

Expected behavior:

$ terragrunt init
my-production-backend-bucket
ERRO[0000] Did not find any Terraform files (*.tf) in /Documents/terragrunt/test 
ERRO[0000] Unable to determine underlying exit code, so Terragrunt will exit with error code 1 

adovy avatar Oct 25 '21 13:10 adovy

I think it is executed twice because run_cmd is invoked in different directories, and result is cached for "command + directory"

terragrunt.hcl:

include {
  path = find_in_parent_folders("terragrunt.hcl")
}

locals {
  common_vars = read_terragrunt_config(find_in_parent_folders("terragrunt.hcl"))
  common_vars2 = read_terragrunt_config(find_in_parent_folders("terragrunt.hcl"))
}

Parent terragrunt.hcl:

locals {
  test = run_cmd("pwd")
}

Execution:

$ terragrunt init
/tmp/run_cmd
/tmp/run_cmd/app
...

was printed only once "/tmp/run_cmd/app" even in locals was included terragrunt.hcl twice

denis256 avatar Oct 25 '21 13:10 denis256

This also happens if you have a dependency or dependencies block in the included terragrunt.hcl file

nguyen-vo avatar Apr 27 '24 17:04 nguyen-vo