This Terraform configuration sets up a Virtual Private Cloud (VPC) and a subnet in Google Cloud Platform (GCP). It utilizes a modular approach, where the VPC setup is encapsulated in a separate module.
Before running this Terraform configuration, ensure you have the following prerequisites:
-
Google Cloud Platform Account: You need an active GCP account with appropriate permissions to create resources like VPCs and subnets.
-
Google Cloud SDK (optional): It's recommended to have the Google Cloud SDK installed for authentication purposes. Refer to the Google Cloud SDK installation guide for instructions.
-
Terraform: Install Terraform on your local machine. Refer to the official Terraform documentation for installation instructions.
-
Service Account Key: You need a service account key with the necessary permissions to create resources on GCP. Download the JSON key file and keep it secure.
If you haven't already configured authentication for Google Cloud, follow these steps:
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your/keyfile.json"git clone https://github.com/Basu-Patil/tf-gcp-infra
cd tf-gcp-infra
terraform initIn the variables.tf file at root directory, adjust the variables according to your requirements. These may include project ID, region, subnet CIDR, etc.
Review the Terraform execution plan to ensure it will create the resources as expected:
terraform planOnce everything looks good, go ahead and apply the plan
terraform applyThe VPC setup is encapsulated within a separate module located in the modules/vpc directory. This modular approach promotes reusability and maintainability.
main.tf: Main Terraform configuration file where the VPC module is called and the VPC and subnet and routes are created. variables.tf: Defines input variables used by the Terraform configuration. providers.tf: Defines the GCP(Google Cloud Platform) providers. modules/vpc/: Directory containing the VPC module.
Example: Cloud storage bucket
terraform import google_storage_bucket.my_bucket your-bucket-name
google_service_networking_connection error: Cannot modify allocated ranges in CreateConnection. Please use UpdateConnection
gcloud beta services vpc-peerings update
--service=servicenetworking.googleapis.com
--ranges=private-ip-address
--network="web-application-vpc-2"
--project="casye6225-dev"
--force
Cloud DNS API
Certificate Manager API