Search code examples
terraformterraform-provider-gcp

How can I use shared VPC GCP in Terraform config?


I have shared VPC configured in GCP, and I would like to know how I can use it in my terrafrom.

Before using shared VPC, my terraform network_interface section is as follows:

network_interface {
    network     = "default"
    address     = "10.128.0.5"
    access_config {
      //nat_ip    = "xxx.xxx.xxx.xx"
    }
  }

I was wondering if someone can guide me on this.

Really appreciated.

Thanks!

-Laurent


Solution

  • I did not try this with terraform but I am pretty sure you can use shared VPC following the sample: https://github.com/terraform-providers/terraform-provider-google/tree/master/examples/shared-vpc

    Your network interface should look like that:

    network_interface {
      network = "${google_compute_network.shared_network.self_link}"
      access_config {
        nat_ip = "..."
      }
    }
    

    Do you need to use a fixed internal IP (through the field address) or can you use an automatically affected address ? If you cannot, you will have to keep the address map somewhere to be sure you do not affect an already affected address.

    The NAT IP should not cause problem but you know... the best answer is to try it and see ;)