Google Compute Engine Subnetwork

This page shows how to write Terraform for Compute Engine Subnetwork and write them securely.

google_compute_subnetwork (Terraform)

The Subnetwork in Compute Engine can be configured in Terraform with the resource name google_compute_subnetwork. The following sections describe 3 examples of how to use the resource and its parameters.

Example Usage from GitHub

github-iconmsfidelis/kubernetes-with-cri-o
resource "google_compute_subnetwork" "private_subnet1a" {
  name          =  format("private-subnet-%sa", var.project_region)
  ip_cidr_range = var.private_subnet_1a
  network       = google_compute_network.vpc_network.self_link
  region        = var.project_region
}
github-iconmbdebian/terraform-playground
resource "google_compute_subnetwork" "eu_deployment" {
  name          = "eu-production-subnet"
  ip_cidr_range = "10.1.0.0/16"
  region        = "europe-west4"
  network       = google_compute_network.vpc_idorg_prod.id
}
github-iconkaks2015/Terraform4-CR460-H2021
resource "google_compute_subnetwork" "mtl-dmz" {
  name          = "mtl-dmz"
  ip_cidr_range = "172.16.1.0/24"
  region        = "us-east1"
  network       = google_compute_network.cr460demo.self_link
}

Parameters

  • creation_timestamp requiredcomputed - string
    • Creation timestamp in RFC3339 text format.

  • description optional - string
    • An optional description of this resource. Provide this property when you create the resource. This field can be set only at resource creation time.

  • fingerprint requiredcomputed - string
    • Fingerprint of this resource. This field is used internally during updates of this resource.

  • gateway_address requiredcomputed - string
    • The gateway address for default routes to reach destination addresses outside this subnetwork.

  • id optionalcomputed - string
  • ip_cidr_range required - string
    • The range of internal addresses that are owned by this subnetwork. Provide this property when you create the subnetwork. For example, 10.0.0.0/8 or 192.168.0.0/16. Ranges must be unique and non-overlapping within a network. Only IPv4 is supported.

  • name required - string
    • The name of the resource, provided by the client when initially creating the resource. The name must be 1-63 characters long, and comply with RFC1035. Specifically, the name must be 1-63 characters long and match the regular expression 'a-z?' which means the first character must be a lowercase letter, and all following characters must be a dash, lowercase letter, or digit, except the last character, which cannot be a dash.

  • network required - string
    • The network this subnet belongs to. Only networks that are in the distributed mode can have subnetworks.

  • private_ip_google_access optional - bool
    • When enabled, VMs in this subnetwork without external IP addresses can access Google APIs and services by using Private Google Access.

  • private_ipv6_google_access optionalcomputed - string
    • The private IPv6 google access type for the VMs in this subnet.

  • project optionalcomputed - string
  • region optionalcomputed - string
    • The GCP region for this subnetwork.

  • secondary_ip_range optionalcomputed - list / object
    • An array of configurations for secondary IP ranges for VM instances contained in this subnetwork. The primary IP of such VM must belong to the primary ipCidrRange of the subnetwork. The alias IPs may belong to either primary or secondary ranges. Note: This field uses attr-as-block mode to avoid breaking users during the 0.12 upgrade. To explicitly send a list of zero objects you must use the following syntax: 'example=[]' For more details about this behavior, see this section.

  • self_link requiredcomputed - string

Explanation in Terraform Registry

A VPC network is a virtual version of the traditional physical networks that exist within and between physical data centers. A VPC network provides connectivity for your Compute Engine virtual machine (VM) instances, Container Engine containers, App Engine Flex services, and other network-related resources. Each GCP project contains one or more VPC networks. Each VPC network is a global entity spanning all GCP regions. This global VPC network allows VM instances and other resources to communicate with each other via internal, private IP addresses. Each VPC network is subdivided into subnets, and each subnet is contained within a single region. You can have more than one subnet in a region for a given VPC network. Each subnet has a contiguous private RFC1918 IP space. You create instances, containers, and the like in these subnets. When you create an instance, you must create it in a subnet, and the instance draws its internal IP address from that subnet. Virtual machine (VM) instances in a VPC network can communicate with instances in all other subnets of the same VPC network, regardless of region, using their RFC1918 private IP addresses. You can isolate portions of the network, even entire subnets, using firewall rules. To get more information about Subnetwork, see:

Frequently asked questions

What is Google Compute Engine Subnetwork?

Google Compute Engine Subnetwork is a resource for Compute Engine of Google Cloud Platform. Settings can be wrote in Terraform.

Where can I find the example code for the Google Compute Engine Subnetwork?

For Terraform, the msfidelis/kubernetes-with-cri-o, mbdebian/terraform-playground and kaks2015/Terraform4-CR460-H2021 source code examples are useful. See the Terraform Example section for further details.

security-icon

Scan your IaC problem in 3 minutes for free

You can keep your IaC security for free. No credit card required.