简体   繁体   English

通过 Terraform 配置没有外部 IP 的 GCP VM 实例

[英]Provision a GCP VM instance with no external IP via Terraform

Trying to create a VM in GCP via terraform with External IP as None.尝试通过 terraform 在 GCP 中创建 VM,外部 IP 为 None。

network_interface {
  network = "projects/other-project-name/global/networks/network-name"
  subnetwork = "projects/other-project-name/regions/us-central1/subnetworks/subnet-name"
  access_config {
    nat_ip = "None"
  }
}  

But nat_ip = "None" is invalid value for the field.但是nat_ip = "None"是该字段的无效值。 And if I do nat_ip = "" , it auto assigns External IP.如果我执行nat_ip = "" ,它会自动分配外部 IP。
Here's their documentation: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_instance#nat_ip这是他们的文档: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_instance#nat_ip

To create a VM in GCP via terraform without External IP, you can just omit the access_config section in network_interface block, as documented here .要在没有外部 IP 的情况下通过 terraform 在 GCP 中创建 VM,您可以省略network_interface块中的access_config部分,如此所述。 So you'd have just:所以你只需要:

network_interface {
  network = "projects/other-project-name/global/networks/network-name"
  subnetwork = "projects/other-project-name/regions/us-central1/subnetworks/subnet-name"
}

Something has changed in the recent updates of the google provider and I couldn't resolve this problem until I've downgraded the network tier to standard, any other combination with network tier PREMIUM (default) or the omission of the block leads to VMs with ephemeral IPs谷歌提供商的最近更新发生了一些变化,直到我将网络层降级为标准,与网络层 PREMIUM(默认)的任何其他组合或块的省略导致 VM 与临时 IP

access_config {
      nat_ip = ""
      network_tier = "STANDARD"
}

I confirm the above behavior, as mentioned by LundinCast .LundinCast所述,我确认上述行为。 In my case, I was not seeing the External IP configured for the VM I was creating using Terraform.就我而言,我没有看到为我使用 Terraform 创建的 VM 配置的外部 IP。 I added the blank access_log block under network_interface section, and I got the external ip configured.我在 network_interface 部分下添加了空白的 access_log 块,并配置了外部 ip。

network_interface {
      network = "default"
      access_config {
      }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过Terraform为GCP VM实例配置静态IP - Provision a GCP VM instance with Static IP via Terraform 有条件地使用 terraform 供应 gcp 虚拟机实例 - Conditionally provision a gcp vm instance with terraform 如何通过 Terraform 从同一模板创建两个具有不同 static 外部 IP 的 GCP VM 实例? - How to create two GCP VM instances with deferent static external IP from same template via Terraform? 尽管 apache2 已启动,但无法通过外部 IP 访问 GCP VM 实例 - Can not access to GCP VM Instance via external IP although apache2 started 通过 terraform 创建 gcp vm 实例时出错 - Error when creating gcp vm instance via terraform 无法从外部 IP 访问 GCP 虚拟机实例 - GCP VM instance cannot be accessed from external IP GCP 多个外部 static IP 地址到 Instance VM 别名 IP NIC0 - GCP multiple external static IP addresses to Instance VM alias IP NIC0 Terraform GCP vm 实例创建 - 错误 403 - Terraform GCP vm instance create - Error 403 Ansible“gcp_compute_instance”模块不会将外部 IP 分配给 VM 实例 - Ansible "gcp_compute_instance" module won't assign External IP to VM instance ansible gcp_compute_instance - 在创建 vm 实例时附加现有的外部 ip 地址 - ansible gcp_compute_instance - attach existing external ip address when creating vm instance
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM