Search code examples
google-cloud-platformterraform-provider-gcp

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


Solution

  • 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"
      
      #omit the access_config section to ignore external ips
      #access_config {
      #}
    }