如何将公共和私有保留IP附加到GCE实例?

问题描述 投票:0回答:1

https://www.terraform.io/docs/providers/google/r/compute_instance.html

我想保留外部和内部 IP,但如何附加两者?我在 TF 文档中没有看到示例。

它只有

network_ip - (Optional) The *private* IP address ...
https://www.terraform.io/docs/providers/google/r/compute_instance.html#network_interface

google-cloud-platform google-compute-engine terraform
1个回答
3
投票

这是我的计算实例模块中的一个工作示例:

resource "google_compute_address" "internal" {
  name         = "${var.NAME}-int-ip"
  subnetwork   = "${var.SUBNETWORK}"
  address_type = "INTERNAL"
  address      = "${var.PRIVATE_IP}"
  region       = "${var.REGION}"
}

resource "google_compute_address" "external" {
  name         = "${var.NAME}-ext-ip"
  address_type = "EXTERNAL"
  region       = "${var.REGION}"
}

然后在 google_compute_instance 资源块中设置 network_infrastructure 块中的 IP:

network_interface {
   network= "${var.NETWORK}"
   network_ip = "${google_compute_address.internal.address}"
   access_config {
      nat_ip = "${google_compute_address.external.address}" 
   }
© www.soinside.com 2019 - 2024. All rights reserved.