terraform-provider-google/examples/shared-vpc
2018-10-02 16:07:28 -07:00
..
scripts Add an example of use of shared VPC networking. (#810) 2017-12-06 14:52:48 -08:00
.gitignore Add an example of use of shared VPC networking. (#810) 2017-12-06 14:52:48 -08:00
main.tf Deprecate assigned_nat_ip in compute_instance family (#2155) 2018-10-02 16:07:28 -07:00
output.tf Deprecate assigned_nat_ip in compute_instance family (#2155) 2018-10-02 16:07:28 -07:00
README.md Add an example of use of shared VPC networking. (#810) 2017-12-06 14:52:48 -08:00
terraform.tfvars.example Add an example of use of shared VPC networking. (#810) 2017-12-06 14:52:48 -08:00
variables.tf terraform fmt on examples (#1148) 2018-03-02 16:16:20 -08:00

Shared Virtual Private Cloud Networking in Google Cloud

This is a template showcasing the shared VPC feature in Google Cloud. It features four projects:

  • A host project, which owns a VPC
  • Two service projects, each of which owns a VM connected to the VPC
  • A fourth project, which owns a VM not connected to the VPC.

It is based on the diagram in the overview at https://cloud.google.com/vpc/docs/shared-vpc.

Begin by downloading your credentials from Google Cloud Console; the default path for the downloaded file is ~/.gcloud/Terraform.json. If you use another path, update the credentials_file_path variable. Ensure that these credentials have Organization-level permissions - this example will create and administer projects.

This example creates projects within an organization - to run it, you will need to have an Organization ID. To get started using Organizations, read the quickstart here. Since it uses organizations, project-specific credentials won't work, and consequently this example is configured to use application default credentials. Ensure that the application default credentials have permission to create and manage projects and Shared VPCs (sometimes called 'XPN'). The example also requires you to specify a billing account, since it does start up a few VMs.

After you run terraform apply on this configuration, it will output the IP address of the second service project's VM, which (after it's done starting up) displays a page checking network connectivity to the other two VMs.

Run with a command like:

terraform apply \
        -var="region=us-central1" \
        -var="region_zone=us-central1-f" \
        -var="org_id=1234567" \
        -var="billing_account_id=XXXXXXXXXXXX"