Use a pre-existing subnetwork

Use the pre-existing-subnetwork module to discover an existing subnetwork in Google Cloud and retrieve the subnetwork attributes.

This module lets you integrate your pre-provisioned network infrastructure with new Cluster Toolkit deployments. By using this module, you securely connect new resources, such as virtual machine (VM) instances, to your established network environments without the need to recreate the networks. The module outputs attributes that uniquely identify the subnetwork so that other modules can consume the attributes.

For the complete list of inputs and outputs for this module, see the pre-existing-subnetwork 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-subnetwork module, see the examples/hpc-slurm.yaml file. 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.

Required roles

To get the permissions that you need to discover the pre-existing subnetwork, ask your administrator to grant you the Compute Network Viewer (roles/compute.networkViewer) IAM role on your project. 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.

Configure the module

To identify the subnetwork, you can provide the self-link for the subnetwork. If you provide the subnetwork_self_link variable, then the module ignores the subnetwork_name variable, the region variable, and the project variable.

The following example demonstrates how to discover a subnetwork by using the subnetwork_self_link setting and pass the subnetwork attributes to the vm-instance module. The use keyword instructs the vm-instance module to accept the variables that identify the subnetwork so that the cluster creates the VM inside the correct subnetwork.

- id: network
  source: modules/network/pre-existing-subnetwork
  settings:
    subnetwork_self_link: https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/subnetworks/SUBNETWORK_NAME

- id: example_vm
  source: modules/compute/vm-instance
  use:
  - network
  settings:
    name_prefix: example
    machine_type: c2-standard-4

Replace the following:

  • PROJECT_ID: the ID of the Google Cloud project that owns the subnetwork.
  • REGION: the Google Cloud region where the subnetwork is located.
  • SUBNETWORK_NAME: the name of the pre-existing subnetwork.

What's next