Terraform variables not allowed

Viewed 27

I have a simple use case where I am provisioning a key vault but want to define a variable as its only really needed here (local) but I get the error variable not allowed.

variable "secrets" {
    type = map(string)
    default = {
      "price-cosmos-db-primary-key" = azurerm_cosmosdb_account.acc.primary_key
      "price-cosmos-db-endpoint" = azurerm_cosmosdb_account.acc.endpoint  
    }
}

resource "azurerm_key_vault_secret" "keyvaultsecrets" {
  count = length(local.secrets)
  name = keys(local.secrets)[count.index]
  value = values(local.secrets)[count.index]
  key_vault_id = azurerm_key_vault.price_keyvault.id
  depends_on = [
    azurerm_cosmosdb_account.acc
  ]
}

Is it possible to do the equivalent but using locals?

1 Answers

Use locals, it will work.

locals {
  secrets = {
      "price-cosmos-db-primary-key" = azurerm_cosmosdb_account.acc.primary_key
      "price-cosmos-db-endpoint" = azurerm_cosmosdb_account.acc.endpoint  
    }
}
Related