gpt4 book ai didi

google-cloud-platform - Terraform 配置未在 GCP 上公开 http 端口

转载 作者:行者123 更新时间:2023-12-03 08:18:29 27 4
gpt4 key购买 nike

我正在使用以下 terraform 代码来公开在端口 80 上运行的 http 服务器应用程序。应用 terraform 配置后,当我尝试 curl 或访问公共(public) IP e iget 连接超时。如果我 curl 本地主机,它工作正常。所以问题出在配置上。我缺少任何配置吗?

// Configure the Google Cloud provider
provider "google" {
credentials = file("xxxxxx-13a189a9c1c7.json")
project = "xxxx-xxxx"
region = "us-west1"
}


// Terraform plugin for creating random ids
resource "random_id" "instance_id" {
byte_length = 8
}

// A single Compute Engine instance
resource "google_compute_instance" "default" {
name = "bkps-314318-${random_id.instance_id.hex}"
machine_type = "f1-micro"
zone = "us-west1-a"

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

boot_disk {
initialize_params {
image = "debian-cloud/debian-9"
}
}

metadata = {
ssh-keys = "joao:${file("/home/gc/projetos/gcp/terraform/joaossh.pub")}"
}

metadata_startup_script = file("${path.module}/startup.sh")

network_interface {
network = "default"


access_config {
// Include this section to give the VM an external ip address
// A variable for extracting the external IP address of the instance


}
}
}

output "ip" {
value = google_compute_instance.default.network_interface.0.access_config.0.nat_ip
}



resource "google_compute_firewall" "allow-http" {
name = "http-firewall"
network = google_compute_network.default.name

source_ranges = ["0.0.0.0/0"]

allow {
protocol = "tcp"
ports = ["80", "443", "8080", "1000-4000"]
}

source_tags = ["web"]
}

resource "google_compute_network" "default" {
name = "test-network"
}

enter image description here

enter image description here

enter image description here

最佳答案

在资源部分

resource "google_compute_firewall" "allow-http" {

您定义了要附加防火墙规则的实例:

source_tags = ["web']

解决方案:

在资源部分

resource "google_compute_instance" "default" {

添加以下行:

tags = ["web"]

关于google-cloud-platform - Terraform 配置未在 GCP 上公开 http 端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68614677/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com