Create a VPC in Google Cloud.
The Terraform script below deploys a server under the Google Cloud Always Free tier,
- terraform__gcloud-instance
- GitHub: github.com/k3karthic/terraform__gcloud-vpc
- Codeberg: codeberg.org/k3karthic/terraform__gcloud-vpc
Enable the Compute Engine API from https://console.cloud.google.com/apis/api/compute.googleapis.com/overview?pli=1.
- Create a file to store the Terraform input variables. Use
google.tfvars.sample
as a reference. Keepgoogle.tfvars
as the filename or change the name in the following files,.gitignore
bin/plan.sh
- Set the
region
input variable. Regions available in the free tier (cloud.google.com/free/docs/gcp-free-tier/#compute),- Oregon: us-west1
- Iowa: us-central1
- South Carolina: us-east1
- Keep
us-central1
as the region or change the variable nameuscentral1_cidr
to match the new region.
Google provider documentation is at registry.terraform.io/providers/hashicorp/google/latest/docs.
Google Cloud Shell can deploy this script without configuration.
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
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>