I am working on a module that does the following:
- create a azure subscription
- create a bunch of resources under this subscription
I need to get the ID of the subscription first and pass it on as a Providers configuration to the other modules.
I tried to do exactly what was explained in the documentation about explicitly passing providers in modules but I don’t seem to get it to work.
my parent module has a providers definition like this:
provider “azurerm” {
alias = “alternate”
subscription_id = module.subscription.subscription_id
}
my child module has a reference to this provider like this:
module “resourcegroup” {
source = “./resourcegroup/azurerm”
version = “1.0.1”
location = “westeurope”
resource_group_name = var.resourcegroup_resource_group_name
tags = var.resourcegroup_tags
providers = {
azurerm = azurerm.alternate
}
}
then my child module has a providers block like this:
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
configuration_aliases = [azurerm.alternate]
}
}
}
resource “azurerm_resource_group” “rg” {
provider = azurerm.alternate
name = var.resource_group_name
location = var.location
tags = var.tags
}
but with this I am not able to load the child module into TFE, the error I get is:
Version 1.0.1 Error: error loading the module: Variables not allowed: Variables may not be used here. (in main.tf on line 5)
I am not sure what I am doing wrong here? it seems that variables are not allowed within the required_providers block.