Providers accept variable input

I’d like to get some community feedback to using Providers.

What is occurring is we deploy various services typically all within Azure so therefore we use azurerm providers for all our services. The issue we run into however is when deploying across different subscriptions.

Say we are deploying an Application Gateway into Subscription A but the service we want to connect to the Application Gateway as a backend service resides in Subscription B. To do this we need to pass 2 providers (1 for Sub A, 1 for Sub B). The issue is we have to specify the provider inside the Data or Resource we are deploying.

This in itself is not a major issue as you only really need to pass the provider info down to the one Data or Resource in the other subscription. But now add if you want to be able to deploy a Dev, Qa and Prod instance of this setup, how do you accommodate that without triplicating your templates?

Yes, I know there are “ways” you can still do this and work around the limitation with other processes and functions but would it be easier and make the terraform templates more flexible if the Providers allowed the use of variable input? You could then use conditions in your locals.tf or other location to determine the proper Provider and send it down the line. Thoughts?

terraform {
required_providers {
azurerm = {
source = “hashicorp/azurerm”
version = “~> 4.0”
configuration_aliases = [
azurerm.provider_alias
]
}
}
}

data “azurerm_storage_account” “storageaccount” {
provider = azurerm.provider_alias
resource_group_name = var.resourcegroup
name = var.storageaccount.name
}

Any suggestions that aren’t going to overly complicate the issue is greatly appreciated or let me know if I am way off base here. Thanks!