【发布时间】:2023-04-02 03:30:01
【问题描述】:
我正在尝试创建 Servicebus 主题和订阅,并在引用此 link 并更新了一些内容之后,我尝试为每个主题创建运行,它抛出了错误
│给定的“for_each”参数值不合适:“for_each” 参数必须是映射或字符串集,并且您
gs,你│提供了一个元组类型的值。
这是我正在尝试的
variable "topics" {
type = any
default = [
{
name = "testtopic"
subscriptions = [
{
name = "testsubscription"
rules = [{
name = "SucceededRule",
sql_filter = "Status = 'Succeeded'"
}]
},
{
name = "readysubscription"
rules = [{
name = "ReadyRule",
sql_filter = "Status = 'Ready'"
}]
}
]
}
]
description = "List of topics."
}
locals {
topics = [
for topic in var.topics : merge({
name = ""
status = "Active"
auto_delete_on_idle = null
default_message_ttl = null
enable_batched_operations = null
enable_express = null
enable_partitioning = null
max_size = null
enable_duplicate_detection = null
enable_ordering = null
authorization_rules = []
subscriptions = []
duplicate_detection_history_time_window = null
}, topic)
]}
维护
resource "azurerm_servicebus_topic" "topic" {
for_each = toset(local.topics)
name = each.value.name
resource_group_name = var.resource_group_name
namespace_name = azurerm_servicebus_namespace.servicebus.name
status = each.value.status
auto_delete_on_idle = each.value.auto_delete_on_idle
default_message_ttl = each.value.default_message_ttl
enable_batched_operations = each.value.enable_batched_operations
enable_express = each.value.enable_express
enable_partitioning = each.value.enable_partitioning
max_size_in_megabytes = each.value.max_size
requires_duplicate_detection = each.value.enable_duplicate_detection
support_ordering = each.value.enable_ordering
duplicate_detection_history_time_window = each.value.duplicate_detection_history_time_window
}
【问题讨论】:
-
由于
, topic),您的主题变量确实是一个元组。不知道为什么要在元组中添加主题 -
我也试过没有那个,它没有帮助。我得到的是同样的错误
-
你试过
for_each = local.topics吗? -
是的,同样的反应。
-
我假设这是 locals 中的使用大部分都很好(即某些值似乎未使用)。从语法上看,它似乎也很好,而且我很难将您的错误消息与提供的代码相协调。这可以重现吗?
标签: terraform azureservicebus terraform-provider-azure azure-servicebus-topics