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

dependency block with a relative path does not resolve anymore when included with expose=true #3475

Open
JeanFred opened this issue Oct 15, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@JeanFred
Copy link
Contributor

Describe the bug

If a dependency block with a relative path is present in a file that is included, the path resolution stops working when that file is included with expose=true.

Steps To Reproduce

I have a repo which follows the _envcommon pattern described in the live-example − here is a reconstructed, minimal reproduction:

.
├── environments
│   ├── _envcommon
│   │   └── b.hcl
│   ├── qc
│   │   └── eu-west-1
│   │       ├── a
│   │       │   └── terragrunt.hcl
│   │       └── b
│   │           └── terragrunt.hcl
│   └── terragrunt.hcl
└── layers
      ├── a
      │   └── main.tf
      └── b
          └── main.tf

b.hcl

terraform {
  source = "${dirname(find_in_parent_folders())}/..//layers/b"
}

dependency "a" {
  config_path = "../a/"
}

inputs = {
  region = dependency.a.outputs.region
}

qc/eu-west-1/a/terragrunt.hcl

include "root" {
  path = find_in_parent_folders()
}

terraform {
  source = "${dirname(find_in_parent_folders())}/..//layers/a"
}

qc/eu-west-1/b/terragrunt.hcl

include "root" {
  path = find_in_parent_folders()
}

include "envcommon" {
  path   = "${dirname(find_in_parent_folders())}/_envcommon/b.hcl"
  expose = true
}

When expose=true is commented out, all is fine − a Terraform plans runs successfully, and the output from a is passed to b

With expose=true, the plan fails with
On latest Terragrunt 0.68.1:

21:06:42.299 ERROR  stat ../../../a: no such file or directory
21:06:42.299 ERROR  Unable to determine underlying exit code, so Terragrunt will exit with error code 1

on Terragrunt 0.60.1

level=warning msg=Error reading file terraform-test/environments/a: open terraform-test/environments/a: no such file or directory
level=error msg=open terraform-test/environments/a: no such file or directory
level=error msg=Unable to determine underlying exit code, so Terragrunt will exit with error code 1

Expected behavior

The dependency keeps working even after using expose=true − or it never works! But it behaves consistently.

Versions

  • Terragrunt version: 0.60.1 ; also retested with latest 0.68.1
  • OpenTofu/Terraform version: 1.7.5
  • Environment details: Ubuntu 20.04

Additional context

I guess I will try using some combination of path_relative_to_include, path_relative_from_include, get_terragrunt_dir and friends until it works :)

@JeanFred JeanFred added the bug Something isn't working label Oct 15, 2024
@JeanFred
Copy link
Contributor Author

JeanFred commented Oct 15, 2024

I guess I will try using some combination of path_relative_to_include, path_relative_from_include, get_terragrunt_dir and friends until it works :)

Ha! It was easier than I thought. This does the trick:

dependency "a" {
  config_path = "${get_terragrunt_dir()}/../a/"
}

@denis256
Copy link
Member

Hi,
I think can be also used path_relative_to_include or get_repo_root(to pass path relative from repo root):

config_path = "${path_relative_to_include()}/../a/"

References:

https://terragrunt.gruntwork.io/docs/reference/built-in-functions/#path_relative_to_include

https://terragrunt.gruntwork.io/docs/reference/built-in-functions/#get_repo_root

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
None yet
Development

No branches or pull requests

2 participants