首页 > 解决方案 > Terraform - 除非启用,否则不要在防火墙规则上创建 log_config

问题描述

我正在尝试在 GCP 中创建一些防火墙规则,这些规则可以选择打开或关闭日志记录。

resource "google_compute_firewall" "this" {
  name          = var.name
  project       = var.project
  network       = var.network
  source_ranges = var.source_ranges
  source_tags   = var.source_tags
  target_tags   = var.target_tags
  priority      = var.priority
  direction     = var.direction

  allow {
    protocol = lower(var.protocol)
    ports    = var.ports
  }

  ##  If log_config is defined, this enables logging. By not defining it, we are disabling logging.
  log_config {
            metadata = var.log_metadata
  } 
}

我需要实现并且无法弄清楚的是,当我将 var.firewall_logging 设置为 true (或其他字符串,如果我们不能使用布尔值)并且没有 log_config 块时,如何定义 log_config 块当它设置为假时我尝试使用动态,就像我的其他问题Optional fields in resource然而,即使设置为 false,它仍在创建 log_config 块。

标签: terraform

解决方案


推荐阅读