下述法典成功地在各地区的不同资源组群中部署了2×5个分析工作空间。
locals.tf
locals {
resource_groups = {
for k, v in var.workspaces : k => {
location = v.location
}
}
}
main.tf
resource "azurerm_resource_group" "workspaces" {
for_each = local.resource_groups
name = each.key
location = each.value.location
}
resource "azurerm_log_analytics_workspace" "workspaces" {
for_each = var.workspaces
name = each.key
location = each.value.location
resource_group_name = azurerm_resource_group.workspaces[each.key].name
sku = "PerGB2018"
retention_in_days = each.value.retention_in_days
}
variables.tf
variable "workspaces" {
type = map(object({
location = string
retention_in_days = number
}))
default = {
workspace1 = {
location = "australiasoutheast"
retention_in_days = 30
}
workspace2 = {
location = "australiaeast"
retention_in_days = 30
}
# Add more workspaces as needed
}
}
outputs.tf
# Define outputs
output "workspace_ids" {
value = azurerm_log_analytics_workspace.workspaces[*].id
}
output "workspace_names" {
value = azurerm_log_analytics_workspace.workspaces[*].name
}
output "resource_group_ids" {
value = azurerm_resource_group.workspaces[*].id
}
output "resource_group_names" {
value = azurerm_resource_group.workspaces[*].name
}
output "resource_group_locations" {
value = azurerm_resource_group.workspaces[*].location
}
增加产出 我收到以下错误,无法确定原因。