Following terraform folder structure exists:
| components
| - iam
| . - s3
| . -waf
|
| environments
| - production
| - global
| terraform.tfvars
|
| modules
| - environment-global
Within terraform.tfvars file in production global environment, following content exists:
terragrunt {
terraform {
source = "../../../modules/environment-global"
// ...
}
}
// ...
And within environment-global the file includes all component modules like this:
module "iam" {
source = "../../components/iam"
// ...
}
module "s3" {
source = "../../components/s3"
// ...
}
When running
cd ./environments/test/global && terragrunt plan -parallelism=30
I get all kind of errors, whether the file does not exists, or filename is too long to copy, etc.
Anyhow, how to make the following setup work? I used terragrunt-source to point to modules dir, didn't work, I tried with dependencies configuration, still didn't work.
Is it even possible to use Terragrunt with such setup?
I get all kind of errors, whether the file does not exists, or filename is too long to copy, etc.
Please share the exact log output and error messages so we can understand what issue you're hitting.
When running with following setup:
terragrunt {
terraform {
source = "../../../modules/environment-global"
}
}
##################
# AWS
##################
aws_region = "###"
aws_creds = "###"
aws_profile = "####"
##################
# Common
##################
environment = "test"
Following error appears when it tries to init:
[terragrunt] [REDACTED/terraform/environments/test/global] 2019/02/26 13:29:26 Running command: terraform init
Initializing modules...
- module.iam
Getting source "../../components/iam"
Error downloading modules: Error loading modules: error downloading 'file:///REDACTED/terraform/environments/test/global/.terragrunt-cache/components/iam': source path error: stat REDACTED/terraform/environments/test/global/.terragrunt-cache/components/iam: no such file or directory
[terragrunt] 2019/02/26 13:29:26 Hit multiple errors:
exit status 1
Seems to be issue that Terragrunt cannot resolve relative path, so I tried to use double slash (//) within environment-global module as following:
module "iam" {
source = ".//../../components/iam"
}
But following error appear:
Initializing modules...
- module.iam
Getting source ".//../../components/iam"
Error downloading modules: Error loading modules: subdir "../../components/iam" not found
Wherever I put the double slash, same error occurs. How does the path resolving work in such case?
You will need to set the double slash here:
| environments
| - production
| - global
| terraform.tfvars <--
---
terragrunt {
terraform {
source = "../../..//modules/environment-global"
}
}
This determines the "root" search path. In your environment-global module, you can use a relative include:
module "iam" {
source = "../../components/iam"
...
}
That should do the trick.
Thank you very much. Works as expected!
Most helpful comment
You will need to set the double slash here:
This determines the "root" search path. In your
environment-globalmodule, you can use a relative include:That should do the trick.