Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

find_in_parent_folders throws errors and warnings in some cases when used from a dependency #2941

Closed
Heldroe opened this issue Feb 15, 2024 · 7 comments · Fixed by #2947
Closed
Assignees
Labels
bug Something isn't working

Comments

@Heldroe
Copy link

Heldroe commented Feb 15, 2024

Describe the bug
find_in_parent_folders used in dependencies throws errors and warnings. It seems that in dependencies, instead of being searched from the dependency, find_in_parent_folders is searching from the current project instead and throws errors.

This appeared in 0.55.2 and does not appear in 0.55.1.

The project still works but error messages appear which pollute the output:

ERRO[0000] Error: Error in function call

ERRO[0000]   on /<REDACTED>/foo/test/terragrunt.hcl line 4, in include "foo":
ERRO[0000]    4: include "foo" { path = find_in_parent_folders("foo.hcl") }
ERRO[0000]
ERRO[0000] Call to function "find_in_parent_folders" failed:
ParentFileNotFoundError: Could not find a foo.hcl in any
of the parent folders of
/<REDACTED>/bar/terragrunt.hcl.
Cause: Traversed all the way to the root..

ERRO[0000] Error: Unsuitable value type

ERRO[0000]   on /<REDACTED>/foo/test/terragrunt.hcl line 4, in include "foo":
ERRO[0000]    4: include "foo" { path = find_in_parent_folders("foo.hcl") }
ERRO[0000]
ERRO[0000] Unsuitable value: value must be known

WARN[0000] Error reading partial config  for dependency foo: /<REDACTED>/foo/test/terragrunt.hcl:4,24-47: Error in function call; Call to function "find_in_parent_folders" failed: ParentFileNotFoundError: Could not find a foo.hcl in any of the parent folders of /<REDACTED>/foo/test/terragrunt.hcl. Cause: Traversed all the way to the root.., and 1 other diagnostic(s)

To Reproduce
You need the following tree:

  • foo/
    • test/
      • terragrunt.hcl
    • foo.hcl
  • bar/
    • terragrunt.hcl

foo/test/terragrunt.hcl:

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

bar/terragrunt.hcl:

dependency "foo" {
  config_path = find_in_parent_folders("foo/test")
}

Expected behavior
Planning the bar/ project should work without any warnings or errors.

Versions

  • Terragrunt version: 0.55.2
  • Terraform version: 1.3.6
  • Environment details (Ubuntu 20.04, Windows 10, etc.): MacOS 14.1.1 (23B81)

Additional context
Works in 0.55.1

@Heldroe Heldroe added the bug Something isn't working label Feb 15, 2024
@perplexa
Copy link

perplexa commented Feb 16, 2024

I am having a similar problem with get_original_terragrunt_dir now, which always returns the path from terragrunt.hcl of the invoking directory, rather than the path from the terragrunt.hcl that includes the get_original_terragrunt_dir call.

It breaks all sorts of dependencies that have different nesting levels than the current terragrunt.hcl.

I suspect the breaking change was introduced in 8af1118

edit: seems the commit I linked wasn't the cause of it, because that's been included longer. It also broke in 0.55.2 for me. Not having that error in 0.55.1

in my case, a construct like yamldecode(sops_decrypt_file("${get_original_terragrunt_dir()}/../../../../${local.secret_path}")) works when called from owner/terragrunt.hcl, but when i have a relative ../notowner/somepath/terragrunt.hcl that has a dependency on ../../owner/terragrunt.hcl i get the wrong path in get_original_terragrunt_dir and my sops_decrypt_file call fails.

edit2: has been fixed with https://github.com/gruntwork-io/terragrunt/releases/tag/v0.55.6

@denis256 denis256 self-assigned this Feb 16, 2024
@denis256
Copy link
Member

Will take a look for a fix, most probably it is caused by HCL parsing code which looks for skip flag in files

@denis256
Copy link
Member

I suspect the issue was fixed as part of https://github.com/gruntwork-io/terragrunt/releases/tag/v0.55.4 at least in my tests it does not occurring now

Please confirm from your side

@seanmacisaac
Copy link

I had this yesterday evening using 0.55.4, found this issue and downgraded to 0.55.1, and it worked. We have dependencies that use find_in_partent_folders as described in this issue.

@denis256
Copy link
Member

Additional fix included since: https://github.com/gruntwork-io/terragrunt/releases/tag/v0.55.6

@yadamovych
Copy link

yadamovych commented Jun 4, 2024

Hi everyone,

I'm still experiencing this issue with find_in_parent_folders in the latest version.

In the root of our Git repository, there are folders for deployment and infrastructure. When I execute one of the deployment configurations, it contains a dependency on infrastructure.

dependency "eks" {
  config_path = "../../../../../../../infrastructure/accounts/qa-dev/eu-central-1/devx/customer-features/eks/k8s-main"
}

The dependent infrastructure module includes a template file:

include "template" {
  path = "infrastructure/template/general/stage/customer-features/eks/k8s/terragrunt.hcl"
}

The Terragrunt configuration template includes a local block that utilizes the find_in_parent_folders function, which leads to Issues following Terraform version 0.55.1.

locals {
  account_vars = read_terragrunt_config(find_in_parent_folders("account.hcl"))
  region_vars  = read_terragrunt_config(find_in_parent_folders("regional.hcl"))
  stage_vars   = read_terragrunt_config(find_in_parent_folders("stage.hcl"))
}

Error:

ERRO[0001] Error: Error in function call
ERRO[0001] on saas-test1/infrastructure/template/main/general/stage/network/terragrunt.hcl line 6, in locals:
ERRO[0001] 6: account_vars = read_terragrunt_config(find_in_parent_folders("account.hcl"))
ERRO[0001] Call to function "find_in_parent_folders" failed: ParentFileNotFoundError: Could not find an account.hcl in any of the parent folders of saas-test1/infrastructure/template/main/general/stage/network/terragrunt.hcl. Traversed all the way to the root.

Config files are located here:

saas-test1/infrastructure/accounts/qa-dev/eu-central-1/devx/stage.hcl
saas-test1/infrastructure/accounts/qa-dev/eu-central-1/regional.hcl
saas-test1/infrastructure/accounts/qa-dev/account.hcl

Could someone please assist in resolving this?

Thanks for your help!

@2xburnt
Copy link

2xburnt commented Sep 12, 2024

same problem in 0.67.4 find_in_parent_folders searches the path relative to the current *.hcl file not the originating terragrunt.hcl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Development

Successfully merging a pull request may close this issue.

6 participants