I am trying to use an aliased provider within a submodule. I have the proxy config block setup in my sub module and in the root I have the aliased provider which I am passing into the module’s providers config.
However this does not seem to work as I would expect. It seems like terraform is seeing the proxy config in the module as a “real” provider so it never picks up the subscription_id I am setting in root module.
I wonder if this is because azurerm has to have the feature config in the provider? Is there anyway to make this work. I can get it to work by adding the subscription_id to the sub module provider config thus making it a real provider but this is deprecated isn’t it so would rather get it to work the proper way.
Could you share some example code of the implementation?
My understanding is that provider definitions are created within the root module and passed using the provider alias to the module.
# The default "aws" configuration is used for AWS resources in the root
# module where no explicit provider instance is selected.
provider "aws" {
region = "us-west-1"
}
# An alternate configuration is also defined for a different
# region, using the alias "usw2".
provider "aws" {
alias = "usw2"
region = "us-west-2"
}
# An example child module is instantiated with the alternate configuration,
# so any AWS resources it defines will use the us-west-2 region.
module "example" {
source = "./example"
providers = {
aws = aws.usw2
}
}
Hi thanks for reply. I am just trying to do essentially the example below the one from the page you linked and a bit further down it mentions proxy configs. In your example that would replace all uses of the provider which I don’t want in this case. But yes I can provide a code example.
root module
provider "azurerm" {
features {
}
subscription_id = "subscriptionid1"
}
provider "azurerm" {
features {
}
alias = "dev"
subscription_id = "subscriptionid2"
}
module "app_service" {
source = "github.com/repo"
resourcegroup = "resourcegroup"
app_name = "myname"
providers = {
azurerm = azurerm
azurerm.dev = azurerm.dev
}
}
# sub module
# proxy provider config
provider "azurerm" {
# I wonder if this needed features block is stopping this
# provider block being seen as a proxy config?
features {
}
alias = "dev"
# below shouldn't be here it should be picked up from provider
# alias that is passed down from root module. Doesn't seem
# to work however but adding it here does work but is deprecated
# subscription_id = "subscriptionid2"
}
data "azurerm_container_registry" "thing" {
provider = azurerm.dev
name = "registry_name"
resource_group_name = "registry_rg"
}