loop through terraform provider block for multiple subscription

I want to deploy 20 azure resource group in 20 different subscriptions. is there any way i can achieve this with minimum code.

i am using below code.

provider "azurerm" {
    alias = "dev"
    subscription_id = var.network_services_rgs.value.subs
}

resource "azurerm_resource_group" "rg" {
  for_each          = var.network_services_rgs
  provider          = azurerm.dev
  name              = each.key
  location          = each.value.location
  tags              = lookup(each.value, "tags", null)
}

this is for just one RG but how can i extent this to support multiple subscription. i do not want to have 20 providers block for each subscription. please help.

  • 4

    There is no other way as far as I know.

    – 

  • Thanks for the info. i guess i have to use some other method to get this done.

    – 

Leave a Comment