Objectives:
- Understand what VPC network is
- Know to create a VPC network with Terraform on GCP
Prerequisite
- Google Cloud Account
What is VPC network?
A Virtual Private Cloud (VPC) is a virtual network dedicated to your Google Cloud Platform (GCP) project. It provides a way to organize and isolate resources within the GCP environment. With a VPC, you can define IP address ranges, create subnetworks, and configure routes.
You can create the subnetwork in default mode or custom mode.
Code
provider "google" { project = "PROJECT ID" #replace to your project id region = "REGION" #replace to your region zone = "ZONE" #replace to your zone } resource "google_compute_network" "vpc_network" { name = "instruction-415216-network" # replace your unique resource name auto_create_subnetworks = false } resource "google_compute_subnetwork" "default" { name = "instruction-415216-subnet" ip_cidr_range = "10.0.1.0/24" region = "us-west1" network = google_compute_network.vpc_network.id }