I want to deploy my terraform modules in 3 stages due to dependencies. I don't want to define all the dependency/ies in the .hcl files of terragrunt.
In order to achieve this I am overhauling my directory structure. First, everything was in the same directory (i.e. tree /infra-integratiehub/environments/uva-test
). Now I've added a subdirectory like so:
tree /infra-integratiehub/environments/uva-test/basis
├── appconfiguration
│ └── terragrunt.hcl
├── appinsights
│ └── terragrunt.hcl
├── identities
│ └── terragrunt.hcl
├── keyvault
│ └── terragrunt.hcl
├── loganalytics
│ └── terragrunt.hcl
├── networksecuritygroup
│ └── terragrunt.hcl
├── public-ip-addresses
│ └── terragrunt.hcl
├── resourcegroup
│ └── terragrunt.hcl
├── storageaccounts
│ └── terragrunt.hcl
└── subnets-azcli
└── terragrunt.hcl
These files refer to the hcl files with the terragrunt configuration which is at this path: /infra-integratiehub/environments/_env
My modules exist in /infra-integratiehub/modules
.
Here's a tree for further clarification:
/infra-integratiehub
├── environments
│ ├── _env (this has the terragrunt config files)
│ ├── terragrunt.hcl
│ └── uva-test (/basis is the dir in which terragrunt -run-all is executed. With tree shown above)
├── modules (all the tf modules).
When I run terragrunt -run-all plan, it will try to download the modules necessary. The path should be /infra-integratiehub/modules/{modulename}
.
Instead it is: /infra-integratiehub/environments/uva-test/modules
This is (one of) the hcl config files contents:
terraform {
source = "../../modules/appconfiguration"
}
locals {
env_vars = read_terragrunt_config(find_in_parent_folders("env.hcl"))
}
This is the error:
ERRO[0000] Module /infra-integratiehub/environments/uva-test/basis/appconfiguration has finished with an error: downloading source url file:///infra-integratiehub/environments/uva-test/modules/appconfiguration
1 error occurred:
* stat /infra-integratiehub/environments/uva-test/modules/appconfiguration: no such file or directory
prefix=[/infra-integratiehub/environments/uva-test/basis/appconfiguration]
Why is the path to the modules formed as it is?
The origin of the issue is most likely related to the use of get_parent_terragrunt_dir
. I reckon terragrunt uses this inexplicably.
I fixed it (changed it) to use the following:
source =find_in_parent_folders("modules/{modulename}")
This looks for the folder and subfolder combinations in all the loaded files and does the trick.