I am trying to use Terraform and Terragrunt to create a bunch of different resources in Azure. Amongst others, I am deploying subscriptions and resource groups.
I have one central variable file that contains some metadata, and deploys resources based on that. I can deploy all the subscriptions that I want, but I have an issue because I want to deploy resource groups within those subscriptions, and I am not sure how to do it the best way, since the resource group resource doesn't have a subscription parameter.
Variable file looks something like:
inputs = {
departments = [
{
name = "test",
region = "West Europe"
email = "[email protected]"
},
{
name = "test2"
region = "West Europe"
email = "[email protected]"
}
]
}
So in my resource group module I have defined it like this:
resource "azurerm_resource_group" "example" {
for_each = {for dep in var.departments: dep.name => dep}
name = "rg-${each.value.name}"
location = "${each.value.region}"
}
And that is ok, but I need to switch context to the correct subscriptions, so the resource groups are being placed in the proper subs. Any ideas?