Skip to content

k3karthic/terraform__gcloud-vpc

Repository files navigation

Terraform — Create a VPC in Google Cloud

Create a VPC in Google Cloud.

The Terraform script below deploys a server under the Google Cloud Always Free tier,

Code Mirrors

Requirements

Enable the Compute Engine API from https://console.cloud.google.com/apis/api/compute.googleapis.com/overview?pli=1.

Configuration

  1. Create a file to store the Terraform input variables. Use google.tfvars.sample as a reference. Keep google.tfvars as the filename or change the name in the following files,
    1. .gitignore
    2. bin/plan.sh
  2. Set the region input variable. Regions available in the free tier (cloud.google.com/free/docs/gcp-free-tier/#compute),
    1. Oregon: us-west1
    2. Iowa: us-central1
    3. South Carolina: us-east1
  3. Keep us-central1 as the region or change the variable name uscentral1_cidr to match the new region.

Authentication

Google provider documentation is at registry.terraform.io/providers/hashicorp/google/latest/docs.

Google Cloud Shell can deploy this script without configuration.

Deployment

Step 1: Use the following command to create a Terraform plan,

$ ./bin/plan.sh

To avoid fetching the latest state of resources, use the following command,

$ ./bin/plan.sh -refresh=false

Step 2: Review the plan using the following command,

$ ./bin/view.sh

Step 3: Apply the plan using the following command,

$ ./bin/apply.sh

Step 4: Display the created subnetwork using the following command,

$ terraform state show google_compute_subnetwork.uscentral1

terraform show screenshot

Encryption

Encrypt sensitive files (Terraform input variables and state) before saving them. .gitignore must contain the unencrypted file paths.

Use the following command to decrypt the files after cloning the repository,

$ ./bin/decrypt.sh

Use the following command after running bin/apply.sh to encrypt the updated state files,

$ ./bin/encrypt.sh <gpg key id>

Releases

No releases published

Packages

No packages published