I am trying to use map in dynamic block for azurerm_api_management_api. Getting error. Tried different ways, but unable to achieve.
Beow is my variables and resource:
variable "api_names" {
description = "(optional) describe your variable"
type = map(any)
default = {
"example-api" = {
"path" = "example"
"revision" = 1
"protocols" = ["https"]
"content_format" = null
"content_value" = null
},
"example-api2" = {
"path" = "example2"
"revision" = 2
"protocols" = ["https"]
"content_format" = null
"content_value" = null
}
}
}
resource "azurerm_api_management_api" "example" {
for_each = var.api_names
name = each.key
resource_group_name = azurerm_resource_group.example.name
api_management_name = azurerm_api_management.example.name
display_name = each.key
revision = each.value.revision
path = each.value.path
protocols = each.value.protocols
dynamic "import" {
for_each = var.api_names
content {
content_format = each.value.content_format
content_value = each.value.content_value
}
}
}
I have tried for_each = var.api_names[*]
, But no luck.
Getting Error:
Error: import: attribute supports 1 item maximum, config has 2 declared
on modules\apim\resource.tf line 20, in resource "azurerm_api_management_api" "example":
20: resource "azurerm_api_management_api" "example" {
Error: import: attribute supports 1 item maximum, config has 2 declared
on modules\apim\resource.tf line 20, in resource "azurerm_api_management_api" "example":
20: resource "azurerm_api_management_api" "example" {
Is this possible to use as above or am I doing anything wrong.
TIA