【发布时间】:2021-12-19 00:25:25
【问题描述】:
我的 GCP 项目中有一个防火墙规则,并且在运行时从变量中读取值,它可以成功运行,但是我现在有一个用例,我想添加一个拒绝块而不是允许。您不能同时拥有两者,有没有办法根据条件将允许块替换为拒绝块。
也许如果变量名是 X,那么使用拒绝块,或者使用允许块。请参阅下面的示例代码。
resource "google_compute_firewall" "fw" {
....
allow {
protocol = var.somevariable[element(keys(var.somevariable), count.index)]["protocol"]
ports = var.somevariable[element(keys(var.somevariable), count.index)]["ports"]
}
...
}
【问题讨论】:
标签: google-cloud-platform terraform terraform-provider-gcp terraform-template-file