README.md
June 10, 2026 ยท View on GitHub
Description
This module discovers a VPC network that already exists in Google Cloud and outputs network attributes that uniquely identify it for use by other modules. The module outputs are aligned with the vpc module so that it can be used as a drop-in substitute when a VPC already exists.
For example, the blueprint below discovers the "default" global network and the
"default" regional subnetwork in us-central1. With the use keyword, the
vm-instance module accepts the network_self_link and subnetwork_self_link
input variables that uniquely identify the network and subnetwork in which the
VM will be created.
Example
- 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
NOTE: The
project_idandregionsettings would be inferred from the deployment variables of the same name, but they are included here for clarity.
Use shared-vpc
If a network is created in different project, this module can be used to reference the network. To use a network from a different project first make sure you have a cloud nat and IAP forwarding. For more details, refer shared-vpc
License
Copyright 2026 Google LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Requirements
| Name | Version |
|---|---|
| terraform | >= 1.12.2 |
| >= 3.83 |
Providers
| Name | Version |
|---|---|
| >= 3.83 |
Modules
No modules.
Resources
| Name | Type |
|---|---|
| google_compute_network.vpc | data source |
| google_compute_subnetwork.primary_subnetwork | data source |
Inputs
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| network_name | Name of the existing VPC network | string | "default" | no |
| project_id | Project in which the HPC deployment will be created | string | n/a | yes |
| region | Region in which to search for primary subnetwork | string | n/a | yes |
| subnetwork_name | Name of the pre-existing VPC subnetwork; defaults to var.network_name if set to null. | string | null | no |
Outputs
| Name | Description |
|---|---|
| network_id | ID of the existing VPC network |
| network_name | Name of the existing VPC network |
| network_self_link | Self link of the existing VPC network |
| subnetwork | Full subnetwork object in the primary region |
| subnetwork_address | Subnetwork IP range in the primary region |
| subnetwork_name | Name of the subnetwork in the primary region |
| subnetwork_self_link | Subnetwork self-link in the primary region |