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

Failing to resolve modules relative to the base module #260

Open
relu opened this issue Nov 14, 2022 · 2 comments
Open

Failing to resolve modules relative to the base module #260

relu opened this issue Nov 14, 2022 · 2 comments
Assignees

Comments

@relu
Copy link
Contributor

relu commented Nov 14, 2022

It seems there's an issue with how terragrunt-atlantis-config determines module paths when defined in child module .tf files.

The error:

$ terragrunt-atlantis-config_1.16.0_linux_amd64 generate --output atlantis.yaml --autoplan --parallel --create-workspace
INFO[0000] Could not find an old config file. Starting from scratch 
Error: Failed to read module directory: Module directory /tmp/terragrunt-atlantis-config-debug/account/region/env/sub-mod does not exist or cannot be read.

The configuration layout:

.
├── account
│   └── region
│       └── env
│           └── example
│               ├── example.tf
│               └── terragrunt.hcl
├── _modules
│   ├── example
│   │   └── main.tf
│   └── sub-mod
│       └── main.tf
└── terragrunt.hcl

7 directories, 5 files

Describing below the file contents for an example you can use.

  • The root terragrunt.hcl file is empty
  • The _modules/sub-mod/main.tf file is empty
# _modules/example/main.tf
module "example" {
  source = "../sub-mod"
}
# account/region/env/example/terragrunt.hcl
include {
  path = find_in_parent_folders()
}

terraform {
  source = "${get_parent_terragrunt_dir()}/_modules//example"
}
# account/region/env/example/example.tf
module "another" {
  source = "../sub-mod"
}

The problem is with the account/region/env/example/example.tf file which relies on a module that is relative to the parent module in _modules/sub-mod.
Note that this exact configuration works just fine with terragrunt itself (plan/apply).

I'm happy to provide more details if needed.

@Almenon
Copy link
Collaborator

Almenon commented Feb 17, 2024

I don't get it, why is there a terraform file in account/region/env/example/? I've never seen intermixing of Terragrunt and terraform in the same folder before. Also the source in account/region/env/example/example.tf points to a module that doesn't exist, account/region/env/sub-mod

@relu
Copy link
Contributor Author

relu commented Feb 20, 2024

Because this is a feature of Terragrunt, it allows you to add or even override existing files from a base module and refer to resources from within the respective base module since it converges everything. Considering this, terragrunt will correctly evaluate the source relative path source = "../sub-mod" to the parent directory of the base module i.e. _modules/sub-mod and not account/region/env/sub-mod.

You can reproduce this using some null_resource definitions and use a similar file structure as given above, you will see Terragrunt will work correctly with these files while terragrunt-atlantis-config will fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants