Use the pre-existing-vpc module to use an existing Virtual Private Cloud (VPC)
network in Google Cloud and retrieve the network attributes.
This module lets you integrate your pre-provisioned network infrastructure into new Cluster Toolkit deployments. By using this module, you securely connect new resources, such as Compute Engine instances, to your established network environments without the need to recreate the networks. The module outputs attributes that uniquely identify the VPC network and subnetwork so that other modules can consume the attributes.
Because the module outputs align with the standard vpc
module, you can use the pre-existing-vpc
module as a direct substitute.
For the complete list of inputs and outputs for this module, see the
pre-existing-vpc
module
page in the Cluster Toolkit GitHub repository.
Before you begin
Before you begin, verify that you meet the following requirements:
- You have installed and configured Cluster Toolkit. For installation instructions, see Set up Cluster Toolkit.
- You have an existing cluster blueprint. You can use and modify an existing
blueprint or create one from scratch. For a working example of a blueprint
configured for the
pre-existing-vpcmodule, see theexamples/batch.yamlfile. For more information about creating and customizing blueprints, see Cluster blueprint. - To view a complete list of blueprints, go to the Cluster blueprint catalog page.
You can use this module to reference a VPC network in a different Google Cloud project, such as a Shared VPC host project. By default, the module looks up the network and subnetwork in the project that is specified by the deployment's
project_idvariable. To reference a network in a different project, do the following:- Set the
project_idsetting in thesettingsblock of thepre-existing-vpcmodule to the ID of the host project. - Configure a Cloud NAT gateway and Identity-Aware Proxy (IAP) Transmission Control Protocol (TCP) forwarding. For more information, see Cloud NAT overview and Use IAP for TCP forwarding.
- Set the
Required roles
To get the permissions that
you need to discover the pre-existing VPC network and subnetwork,
ask your administrator to grant you the
Compute Network Viewer (roles/compute.networkViewer) IAM role on the project that contains the VPC network (or
the host project for a Shared VPC network).
For more information about granting roles, see Manage access to projects, folders, and organizations.
You might also be able to get the required permissions through custom roles or other predefined roles.
Use an existing VPC
The following example identifies a global network and a regional subnetwork. The
use keyword instructs the vm-instance module to accept the variables that
identify the network and subnetwork so that the cluster creates the compute
instance inside the correct VPC network.
- id: network1
source: modules/network/pre-existing-vpc
settings:
project_id: $(vars.project_id)
region: us-central1
- id: example_vm
source: modules/compute/vm-instance
use:
- network1
settings:
name_prefix: example
machine_type: c2-standard-4
The project_id setting and the region setting are inferred from deployment
variables that share the same name.
Use with a GKE cluster
When you pair the pre-existing-vpc module with the gke-cluster
module to deploy a
Google Kubernetes Engine (GKE) cluster, the existing subnetwork must have
Private Google Access enabled and must
include secondary IP address ranges for pods and services.
Pass the secondary range names to the gke-cluster module by using the
pods_ip_range_name setting and the services_ip_range_name setting, which
default to pods and services:
- id: existing_network
source: modules/network/pre-existing-vpc
settings:
network_name: my-existing-vpc
subnetwork_name: my-existing-subnet
- id: gke_cluster
source: modules/scheduler/gke-cluster
use:
- existing_network
settings:
enable_private_endpoint: false
pods_ip_range_name: pods
services_ip_range_name: services
release_channel: REGULAR
By default, the master_ipv4_cidr_block setting has a null value, so
GKE uses Private Service Connect to prevent /28 CIDR
collisions. For more information about the master_ipv4_cidr_block setting, see
Use a pre-existing VPC
network.
What's next
- For the complete list of inputs and outputs for this module, see the
pre-existing-vpcmodule page in the Cluster Toolkit GitHub repository. - For a complete list of supported modules, see the compatibility matrix on GitHub.