【问题标题】:How to enable Allow HTTP traffic / Allow HTTP traffic on Google Compute Engine with terraform如何使用 terraform 在 Google Compute Engine 上启用允许 HTTP 流量/允许 HTTP 流量
【发布时间】:2021-02-05 23:18:46
【问题描述】:

有没有其他方法可以直接使用 terraform 启用这些规则,而无需在 GCP 中创建单独的防火墙规则,然后将标签附加到计算引擎

目前我正在这样做

    resource "google_compute_firewall" "allow_http" {
  name    = "allow-http-rule"
  network = "default"
  allow {
    ports    = ["80"]
    protocol = "tcp"
  }
  target_tags = ["allow-http"]
  priority    = 1000

}

然后在

中使用这个标签
 resource "google_compute_instance" "app" {
     ...
tags = ["allow-http"]
    }

【问题讨论】:

    标签: google-cloud-platform terraform google-compute-engine terraform-provider-gcp


    【解决方案1】:

    Argument Reference 提到了选项标签。您可以按如下方式使用它:

    ...
      tags = ["http-server","https-server"]
    ...
    

    以同样的方式,您可以使用:gcloud compute instances add-tags 编辑这些值,如下所示:

    要将标签添加到现有 VM 实例,请使用此 gcloud 命令:

    gcloud compute instances add-tags [YOUR_INSTANCE_NAME] --tags http-server,https-server
    

    要在创建实例时添加标签,请在语句中包含该标志:

    gcloud compute instances create [YOUR_INSTANCE_NAME] --tags http-server,https-server
    

    【讨论】:

    • 感谢您的回复,我实际上看到了这个链接,但它只是向实例添加标签,既没有勾选这些框,也没有创建防火墙规则
    【解决方案2】:

    我们需要在我们的网络中同时拥有防火墙规则(http、https)。我们可以在默认网络中看到该标签。

    对我有用

    resource "google_compute_instance" "name" {
     ....
    tags = ["http-server","https-server"]
     ....
    }
    

    【讨论】:

      猜你喜欢
      • 2015-02-06
      • 1970-01-01
      • 2019-07-16
      • 1970-01-01
      • 1970-01-01
      • 2019-02-26
      • 1970-01-01
      • 2020-02-01
      • 1970-01-01
      相关资源
      最近更新 更多