I’m trying to create multiple storage accounts with terraform using below syntax.
What I want to achieve is to create multiple storage accounts with different containers inside of them and generate SAS for those and add all keys to KeyVault using data source but that is another problem as I do not know how to use data:
variable “storage_accounts2” {
type = map(any)
default = {
str1 = { name = “sndbxdatabricks01”
is_hns_enabled = true}
str2 = { name = “testsources12”
is_hns_enabled = false}
}
}
module “storage_account” {
for_each = var.storage_accounts2
source = “central.tfe.pwcinternal.com/ASR/storage-account/azurerm”
version = “11.4.0-3-1.0”
name = each.value[“name”]
location = ukSouth
resource_group_name = Some-resourceGroup-Name
tags = local.tags
tfe_hostname = “https://central.tfe.pwcinternal.com/”
default_action = “Allow”
enabled_threat_protection = true
containers = each.value.containers
is_hns_enabled = each.value[“is_hns_enabled”]
}
Plan is showing that those will be created:
module.storage_account[“str1”].azurerm_advanced_threat_protection.threat will be created
- resource “azurerm_advanced_threat_protection” “threat” {
- enabled = true
- id = (known after apply)
- target_resource_id = (known after apply)
}
module.storage_account[“str1”].azurerm_storage_account.storage will be created
- resource “azurerm_storage_account” “storage” {
…
module.storage_account[“str2”].azurerm_advanced_threat_protection.threat will be created
- resource “azurerm_advanced_threat_protection” “threat” {
- enabled = true
- id = (known after apply)
- target_resource_id = (known after apply)
}
module.storage_account[“str2”].azurerm_storage_account.storage will be created
- resource “azurerm_storage_account” “storage” {
but later, apply fails:
module.storage_account[“str1”].azurerm_storage_account.storage: Still creating… [10s elapsed]
module.storage_account[“str2”].azurerm_storage_account.storage: Still creating… [10s elapsed]
module.storage_account[“str1”].azurerm_storage_account.storage: Still creating… [20s elapsed]
module.storage_account[“str2”].azurerm_storage_account.storage: Still creating… [20s elapsed]
module.storage_account[“str2”].azurerm_storage_account.storage: Still creating… [30s elapsed]
╷
│ Error: retrieving Storage Account: (Name “testsources12” / Resource Group “resourceGroup-Name”): storage.AccountsClient#GetProperties: Failure responding to request: StatusCode=404 – Original Error: autorest/azure: Service returned an error. Status=404 Code=“StorageAccountNotFound” Message=“The storage account testpicisources was not found.”
│
│ with module.storage_account[“str2”].azurerm_storage_account.storage,
│ on .terraform/modules/storage_account/main.tf line 24, in resource “azurerm_storage_account” “storage”:
│ 24: resource “azurerm_storage_account” “storage” {
│
╵
╷
│ Error: retrieving Storage Account: (Name “sndbxdatabricks01” / Resource Group “Some-resourceGroup-Name”): storage.AccountsClient#GetProperties: Failure responding to request: StatusCode=404 – Original Error: autorest/azure: Service returned an error. Status=404 Code=“StorageAccountNotFound” Message=“The storage account sndbxdatabricks01 was not found.”
│
│ with module.storage_account[“str1”].azurerm_storage_account.storage,
│ on .terraform/modules/storage_account/main.tf line 24, in resource “azurerm_storage_account” “storage”:
│ 24: resource “azurerm_storage_account” “storage” {
I’ve also tried with putting storage account names into locals but result was the same.
What I’m doing wrong here? Why it is trying to search for those storage accounts?