简体   繁体   中英

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.

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. And if I do nat_ip = "" , it auto assigns External IP.
Here's their documentation: 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 . 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

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

I confirm the above behavior, as mentioned by LundinCast . In my case, I was not seeing the External IP configured for the VM I was creating using Terraform. I added the blank access_log block under network_interface section, and I got the external ip configured.

network_interface {
      network = "default"
      access_config {
      }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM