-
Clone the repository
git clone https://github.com/afeeney9/TerraformCodebase.git cd TerraformCodebase -
Configure variables
-
Copy
terraform.tfvars.exampletoterraform.tfvarsand update values:project = "your-gcp-project-id" region = "us-central1" zone = "us-central1-a" db_password = "your-db-password"
-
-
Initialize Terraform
terraform init
-
Review the execution plan
terraform plan
-
Apply the configuration
terraform apply
- Confirm with
yeswhen prompted.
- Confirm with
-
Deploy the application
- The VM startup script (
cloud-init.sh) will clone the application from Git and start the service.
- The VM startup script (
-
View Outputs
terraform output
vm_public_ip: Access the web app via this IP.vm_private_ip: VM internal IP.cloud_sql_private_ip: SQL instance private IP.db_connection_name: Cloud SQL connection string.
-
Destroy the environment
terraform destroy
flowchart LR
subgraph VPC [VPC: terraform-network]
Subnet[gallery-subnet<br/>10.0.0.0/16]
VM[Compute Instance<br/>e2-standard-2]
SQL[Cloud SQL<br/>MySQL 8.0]
Bucket[Google Cloud Storage]
end
VM -->|Private IP| SQL
VM -->|Public IP| Client
VM -->|Private IP| Bucket
SQL -.->|Private Service<br/>Peering| VPC
Firewall[Firewall<br/>80,443,3306] --> VM
ServiceAccount --> VM
ServiceAccount --> SQL
- Ensure your public bucket names are globally unique if adding object storage.
- For production deployments, consider using Terraform Cloud or a CI/CD pipeline.
- Secure sensitive variables using Secret Manager or environment variables.
For questions or contributions, please open an issue or submit a pull request.