Skip to main content
Knowledge Base

Multiple terraform sources

Answer

So i have my TG directory structure as below ``` . ├── env1 │   └── applications │   ├── app1 │   │   └── terragrunt.hcl │   ├── app2 │   │   └── terragrunt.hcl │   └── app3 │   └── terragrunt.hcl ├── env2 │   └── applications │   └── app1 │   └── terragrunt.hcl ├── env3 ├── main.hcl └── modules ├── app1 │   ├── main1.tf │   └── main2.tf └── app2 └── main2.tf ``` I have couple of environments `env1, env2, env3`. Each `env` has `app1, app2...` applications. The *applications/app1, applications/app2 ...* directories only contains `terragrunt.hcl` and a `config.tfvars` where i set variables relevant to that app. The `terragrunt.hcl` file is all same. It simply does a `find_in_parent_folders('main.hcl')`. The `main.hcl` simply does a ``` locals { root_dir = get_parent_terragrunt_dir() relative_path = path_relative_to_include() deployment_path_components = compact(split("/", local.relative_path)) app = reverse(local.deployment_path_components)[0] } terraform { source = "${local.root_dir}/..//modules/${local.app}" } ``` The whole idea is that when i execute `terragrunt plan/apply` from say `app2`, it just runs **terraform tf** files from `modules/app2`. The `config.tfvars` of **app2** drives what variation of `app2` it should provision for that environment. This works as expected. However, Now i have a need to **also** run **terraform tf** files from another module (**another/main1.tf and another/main2.tf**) when I run say **app1**. So when I run `terragrunt plan/apply` from say `app1`, it should copy/run whatever is in `modules/app1` + `modules/another`. I have tried using dependency which works but i was trying to see if there was a way to perhaps merge the `source` attribute of `terraform` block to include both this paths or some other better way of doing it ? I want to keep `modules/app1` and `modules/another` as separate modules and include them both via `applications/app1/terragrunt.hcl`. ``` └── modules ├── app1 │   ├── main1.tf │   └── main2.tf └── app2 └── main2.tf └── another └── main1.tf └── main2.tf ``` I also tried multiple includes within `applications/app1/terragrunt.hcl` like below. But i noticed that whatever is the second `terraform source` that gets run. The below would run `tf files` from `modules/another` and not from `modules/app1` ``` include app { terraform { source = <path-to-modules/app1> } } include another { terraform { source = <path-to-modules/another> } } ``` Any guidance would be much appreciated. Thanks. --- <ins datetime="2022-06-10T23:46:05Z"> <p><a href="https://support.gruntwork.io/hc/requests/108752">Tracked in ticket #108752</a></p> </ins>

This is not a supported feature of Terragrunt. The feature request ticket for this is https://github.com/gruntwork-io/terragrunt/issues/1462, but as indicated [in this comment](https://github.com/gruntwork-io/terragrunt/issues/1462#issuecomment-742559624), supporting that operating model requires a major overhaul of Terragrunt internals. The best workaround currently is to generate a Terraform module that calls those modules using `module` blocks on the fly using `generate` blocks.