Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google cloud platform 如何添加默认允许http`_Google Cloud Platform_Google Compute Engine_Terraform - Fatal编程技术网

Google cloud platform 如何添加默认允许http`

Google cloud platform 如何添加默认允许http`,google-cloud-platform,google-compute-engine,terraform,Google Cloud Platform,Google Compute Engine,Terraform,如何将terraform脚本中的默认允许http防火墙规则添加到Google云计算实例 provider "google" { credentials = file("CREDENTIAL_FILE") project = "gitlab-project" region = var.region } resource "google_compute_instance" "gitlab" { name = var.machine_specs.name

如何将terraform脚本中的
默认允许http
防火墙规则添加到Google云计算实例

provider "google" {
    credentials = file("CREDENTIAL_FILE")
    project = "gitlab-project"
    region = var.region
}

resource "google_compute_instance" "gitlab" {
  name          = var.machine_specs.name
  machine_type  = var.machine_type.emicro
  zone          = var.zone

  boot_disk {
    initialize_params {
        image = var.machine_specs.os
        size = var.machine_specs.size
    }
  }

  network_interface {
    # A default network is created for all GCP projects
    network     = "default"
    access_config {
      nat_ip = google_compute_address.static.address
    }
  }

    // Add the SSH key
    metadata = {
        ssh-keys = "martin:${file("~/.ssh/id_rsa.pub")}"
    }

}

// A variable for extracting the external ip of the instance
output "ip" {
 value = "${google_compute_instance.gitlab.network_interface.0.access_config.0.nat_ip}"
}

resource "google_compute_address" "static" {
  name = "ipv4-address"
  address_type = "EXTERNAL"
  address = "XXX.XXX.XXX.XXX"
}

resource "google_compute_firewall" "allow-http" {
  name = "default-allow-http"
  network = 

  allow{
    protocol = "tcp"
    ports = ["80"]
  }
}




您需要将标签
[“http服务器”、“https服务器”]
添加到您的资源组
google\u compute\u实例中,如下所示:

[...]

resource "google_compute_instance" "gitlab" {
  name          = var.machine_specs.name
  machine_type  = var.machine_type.emicro
  zone          = var.zone

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

[...]

只需将标签
http服务器
https服务器
添加到
google\u cloud\u实例
resource groop。 这些标记可以在GCloud控制台的防火墙设置中找到。

您可以使用
google\u compute\u instance
资源中提供的参数

它看起来像:

resource "google_compute_instance" "gitlab" {
  name          = var.machine_specs.name
  machine_type  = var.machine_type.emicro
  zone          = var.zone

  tags = ["http-server"]
http服务器
标记用于
默认允许http
防火墙规则。 如果需要
default allow https
,只需将
https服务器
附加到标记列表中即可


希望这能有所帮助。

考虑使用此工具,从现有环境中构建地形。。。你可以从那里看到你可能需要什么。。。运行此操作,但仍然没有获得默认的允许http防火墙规则。。。我有什么遗漏吗?你能分享“gcloud计算防火墙规则描述默认允许http”的输出吗?