In short, yes, the two files snippets you've posted would work.
terragrunt doesn't support multiple sources and we can only call one module at a time.
Longer answer: It's useful to think of the terraform { ... }
block in your terragrunt.hcl
as a pointer to a "root terraform module". This root module is just any other terraform module, but is special because it is at the root, or the top, of all your terraform config.
So terragrunt only supports one root module, but that root module can use as many additional modules as you need.
The power terragrunt gives us is the ability to re-use these root modules. In vanilla terraform you cannot re-use this root modules.
In your example the terragrunt file is pointing to a root module in the same file (./main.tf
). This works just fine, but because we use terragrunt to keep things DRY we would normally put this root module in a different directory, perhaps even in a git repo and reference it appropriately in the terragrunt.hcl file
Here is a quick diagram:
+-------------------------------+
| /my/root-module |
| |
| main.tf |
| |
+--------------+----------------+
+------------------+ | +----------------+
| /my/modules/vpc | | | /my/modules/s3 |
| | | | |
| module "foo" <----+----> module "bar" |
| | | |
| | | |
+------------------+ +----------------+
Not shown is the terragrunt.hcl file that would point to /my/root-module
, this can be somewhere else on disk or in git.