terragrunt
terragrunt copied to clipboard
terragrunt plan/apply dependency warnings
Describe the bug I believe this bug is somewhat related to gruntwork-io/terragrunt#3028. In some dependency cases, partial config fails to load.
To Reproduce create HCL A create HCL B where A is a dependency create HCL C that is includes B create HCL D where C is a dependency set path as follows: (use relative paths in dependency and include)
first/
B
second/
A
C
D
Expected behavior
Runing terragrunt plan
in C or D works.
What actually happens C works correctly, but D shows the following warnings (but does not fail the command)
WARN[0026] Error reading file <absolute path to A>: open <absolute path to A>: no such file or directory
WARN[0026] Error reading partial config for dependency C: open <absolute path to A>: no such file or directory
Versions
- Terragrunt version: 1.7.5
- Terraform version: 0.57.5
I aggree! Same issue at my side at the same process.
Versions
- Terragrunt version: 0.57.13
- Terrafrom version: 1.8.2
Hey @ben-dov, I wasn't able to repro the issue, the test config I used https://github.com/levkohimins/terragrunt-issue-3080. Can you confirm that the issue is resolved? If not, please provide test configs to reproduce it.
Hey @levkohimins, I tested and found what is missing in your repo to match my case (I probably was unclear).
in order to encounter my bug you just need to change the path in first/b/terragrunt.hcl
from ../../second/a
to ../a
(use relative path of C to A).
after changing, you will see that plans running on C work fine, but plans on D have a warning (but otherwise seem to work).
Hey @ben-dov, Thanks for clarifying. I dare say, just the opposite, the previous behavior before v0.55.6 was incorrect. It makes sense and is intuitive when the relative path is calculated from the location of the included file, not from where it is included. In your case, you need to use the path_relative_to_include()
function.
dependency "a" {
config_path = "${path_relative_to_include()}/../a"
}
Please let me know if this doesn't solve your problem.
hey @levkohimins, if so, it is still weird that runnning C directly causes no warning,
Anyway, I attempted the change and it works in this simple scenario, but not it in others.
New example changes
- in
b
, hangeconfig_path
to${path_relative_to_include()}/../a
(as per your suggestion) - Add the directory
second
under another parent namedinto_second
- Fix path in
c
, changeinclude "b"
path
from../../first/b/terragrunt.hcl
to../../../first/b/terragrunt.hcl
Expected behavior
Runing terragrunt plan
in C or D works.
What actually happens
C returns an error:
ERRO[0000] <project-root>/into_second/into_second/second/a does not exist
ERRO[0000] Unable to determine underlying exit code, so Terragrunt will exit with error code 1
D also errors with:
WARN[0000] Error reading file <project-root>/into_second/into_second/second/a: open <project-root>/into_second/into_second/second/a: no such file or directory
ERRO[0000] open <project-root>/into_second/into_second/second/a: no such file or directory
ERRO[0000] Unable to determine underlying exit code, so Terragrunt will exit with error code 1
hi @ben-dov,
I missed one point, since path_relative_to_include()
returns a relative path from the b
dir, config_path
is assigned to ../../into_second/second/c/
+ ../a
, but including is happening from c
directory and when we actually include the dependency a
, we calculate the absolute path from the directory c
and it looks like this
into_second/second/c/
+ ../../into_second/second/c/
+ ../a
=> into_second/into_second/second/a
.
Thus, we have to build the relative path from the c
directory, for this we need to use another func, path_relative_from_include()
, and in the end it should look like this:
dependency "a" {
config_path = "${path_relative_from_include()}/${path_relative_to_include()}/../a"
}
into_second/second/c/
+ ../../../first/b/
+ ../../into_second/second/c/
+ ../a
=> into_second/second/a
I hope this helped you solve the issue.
THX @levkohimins for the quick response,
Running terragrunt plan
on c
works without issues,
but running on d
prints the warning (but does not fail), kinda like the first problem:
WARN[0000] Error reading file <partial-absolute-path>/into_second/second/a: open <partial-absolute-path>/into_second/second/a: no such file or directory
WARN[0000] Error reading partial config for dependency c: open <partial-absolute-path>/into_second/second/a: no such file or directory
what seems to be missing now is the parent the project directory in partial-absolute-path
I attempted to add another directory pre_into
that will contain into_second
, but the project directory was still missing from the path when running from d
hey @levkohimins, I am usure if this is the correct thing to do, but I noticed changing config_path
in b
to "${get_terragrunt_dir()}/../a"
seems to work in both c
and d
hey @ben-dov
Running
terragrunt plan
onc
works without issues, but running ond
prints the warning (but does not fail), kinda like the first problem:WARN[0000] Error reading file <partial-absolute-path>/into_second/second/a: open <partial-absolute-path>/into_second/second/a: no such file or directory WARN[0000] Error reading partial config for dependency c: open <partial-absolute-path>/into_second/second/a: no such file or directory
This is a bug. I will try to fix it in a while.
I am usure if this is the correct thing to do, but I noticed changing config_path in b to "${get_terragrunt_dir()}/../a" seems to work in both c and d.
It's great that you found a workaround.