【问题标题】:How do I attach a public AND private reserved IP to a GCE instance?如何将公共和私有保留 IP 附加到 GCE 实例?
【发布时间】:2019-03-13 16:26:03
【问题描述】:

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

我想保留一个外部 IP 和一个内部 IP,但如何同时附加?我在 tf 文档中没有看到示例。

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

【问题讨论】:

  • 作为一个附带问题。您是否有需要分配静态私有 IP 地址的特定设计要求?通常,您让 DHCP 服务器分配私有 IP 地址,并使用主机名引用这些实例。对等使这变得复杂,因此有正当的理由。只是思考的食物。

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


【解决方案1】:

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

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}" 
   }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-24
    • 2014-06-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多