用于防火墙日志配置的 Terraform 动态块
Terraform Dynamic Block for Firewall log config
感谢您的帮助和提前花费的时间。
我正在尝试为 AWS 网络防火墙配置创建 terraform 模块。
下面是我的代码:
firewall_arn = var.firewall_arn
logging_configuration {
dynamic "config" {
for_each = var.log_destination_configs
content {
log_destination {
bucketName = lookup(config.value, "bucketName", null)
prefix = lookup(config.value, "prefix", null)
logGroup = lookup(config.value, "logGroup", null)
deliveryStream = lookup(config.value, "deliveryStream", null)
}
log_destination_type = lookup(config.value, "log_destination_type", null)
log_type = lookup(config.value, "log_type", null)
}
}
}
}
然而,当我尝试编译时,出现以下错误:
Error: Unsupported block type
on ../../main.tf line 4, in resource "aws_networkfirewall_logging_configuration" "default":
4: dynamic "config" {
Blocks of type "config" are not expected here.
}
是否因为我在 logging_configuration 内声明块而这是不允许的?
再次感谢。
根据 logging_configuration argument documentation,嵌套块被命名为 log_destination_config
而不是 config
。这就是错误消息指出块 config
不应出现在该块中的原因。如果相应地更新块名称和 lambda 范围变量:
logging_configuration {
dynamic "log_destination_config" {
for_each = var.log_destination_configs
content {
log_destination {
bucketName = lookup(log_destination_config.value, "bucketName", null)
prefix = lookup(log_destination_config.value, "prefix", null)
logGroup = lookup(log_destination_config.value, "logGroup", null)
deliveryStream = lookup(log_destination_config.value, "deliveryStream", null)
}
log_destination_type = lookup(log_destination_config.value, "log_destination_type", null)
log_type = lookup(log_destination_config.value, "log_type", null)
}
}
}
那么应该可以解决与您的错误消息相关的问题。
感谢您的帮助和提前花费的时间。
我正在尝试为 AWS 网络防火墙配置创建 terraform 模块。
下面是我的代码:
firewall_arn = var.firewall_arn
logging_configuration {
dynamic "config" {
for_each = var.log_destination_configs
content {
log_destination {
bucketName = lookup(config.value, "bucketName", null)
prefix = lookup(config.value, "prefix", null)
logGroup = lookup(config.value, "logGroup", null)
deliveryStream = lookup(config.value, "deliveryStream", null)
}
log_destination_type = lookup(config.value, "log_destination_type", null)
log_type = lookup(config.value, "log_type", null)
}
}
}
}
然而,当我尝试编译时,出现以下错误:
Error: Unsupported block type
on ../../main.tf line 4, in resource "aws_networkfirewall_logging_configuration" "default":
4: dynamic "config" {
Blocks of type "config" are not expected here.
}
是否因为我在 logging_configuration 内声明块而这是不允许的?
再次感谢。
根据 logging_configuration argument documentation,嵌套块被命名为 log_destination_config
而不是 config
。这就是错误消息指出块 config
不应出现在该块中的原因。如果相应地更新块名称和 lambda 范围变量:
logging_configuration {
dynamic "log_destination_config" {
for_each = var.log_destination_configs
content {
log_destination {
bucketName = lookup(log_destination_config.value, "bucketName", null)
prefix = lookup(log_destination_config.value, "prefix", null)
logGroup = lookup(log_destination_config.value, "logGroup", null)
deliveryStream = lookup(log_destination_config.value, "deliveryStream", null)
}
log_destination_type = lookup(log_destination_config.value, "log_destination_type", null)
log_type = lookup(log_destination_config.value, "log_type", null)
}
}
}
那么应该可以解决与您的错误消息相关的问题。