gpt4 book ai didi

terraform - 如何将静态 IP 映射到 terraform google 计算引擎实例?

转载 作者:行者123 更新时间:2023-12-03 13:43:27 25 4
gpt4 key购买 nike

我正在将 terraform 与 google vm provider 一起使用。我想将现有的静态 IP 分配给 VM。

代码 :

resource "google_compute_instance" "test2" {
name = "dns-proxy-nfs"
machine_type = "n1-standard-1"
zone = "${var.region}"

disk {
image = "centos-7-v20170719"
}

metadata {
ssh-keys = "myuser:${file("~/.ssh/id_rsa.pub")}"
}

network_interface {
network = "default"
access_config {
address = "130.251.4.123"
}
}
}

但它因错误而失败:

google_compute_instance.test2: network_interface.0.access_config.0: invalid or unknown key: address



我怎样才能解决这个问题?

最佳答案

您还可以允许 terraform 为您创建静态 IP 地址,然后通过对象名称将其分配给实例。

resource "google_compute_address" "test-static-ip-address" {
name = "my-test-static-ip-address"
}

resource "google_compute_instance" "test2" {
name = "dns-proxy-nfs"
machine_type = "n1-standard-1"
zone = "${var.region}"

disk {
image = "centos-7-v20170719"
}

metadata {
ssh-keys = "myuser:${file("~/.ssh/id_rsa.pub")}"
}

network_interface {
network = "default"
access_config {
nat_ip = "${google_compute_address.test-static-ip-address.address}"
}
}
}

关于terraform - 如何将静态 IP 映射到 terraform google 计算引擎实例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45359189/

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