I am trying to create multiple Azure Storage Accounts with set of containers counts, however I couldn't achieve due to multiple resources blocks. As of the below code that I wrote which creates multiple containers in the one storage account. How can I achieve same to create multiple containers in different storage accounts ?
resource "azurerm_resource_group" "rg" {
name = "test-rg"
location = "eastus"
}
variable "storageaccountname" {
type = string
default = "storageaccount1"
}
variable "containers_list" {
type = list
default = [{ name = "sa1container1", access_type = "private" }, {name = "sa1container2", access_type = "private" },{name = "sa1container3", access_type = "private" }]
}
resource "azurerm_storage_account" "storageaccount" {
name = var.storageaccountname
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
account_tier = "Standard"
account_replication_type = "LRS"
}
resource "azurerm_storage_container" "container" {
count = length(var.containers_list)
name = var.containers_list[count.index].name
storage_account_name = azurerm_storage_account.storageaccount.name
container_access_type = var.containers_list[count.index].access_type
}