This project automates the deployment of a full-stack infrastructure on Google Cloud Platform (GCP) using Terraform and Docker. It specifically provisions a Virtual Machine (VM) and automatically deploys the Inception project (a LEMP stack in Docker) upon startup.
- 🚀 Terraform provisions a GCP Compute Engine instance.
- 🔑 Metadata is used to securely pass the
.envconfiguration to the instance. - ⚙️ Startup Script (
startup-instance.sh) runs automatically on the VM to:- Install Docker and Docker Compose.
- Clone the Inception repository.
- Retrieve the
.envfrom metadata and place it in the correct location. - Build and launch the Docker containers using
make.
main.tf: Terraform configuration defining the VM instances, networking, and firewall rules. Supports scaling vianode_count.launch-vm.sh: A wrapper script that initializes Terraform, applies the configuration, and monitors the startup of all instances in parallel.startup-instance.sh: The script that runs inside each VM to bootstrap the environment and deploy the application.setup_ubuntu.sh: A local helper script to install Terraform and the Google Cloud CLI on your Ubuntu machine.
- 🛠️ Virtualized Environment (Optional): Vagrant and VirtualBox if using the automated setup.
- 🧩 Terraform (if running locally).
- 🔧 Google Cloud SDK (gcloud) (if running locally).
- 🌐 A GCP project with a service account key (
cloud-1-key.json).
Choose the setup that best fits your environment:
If you are on an Ubuntu machine and have permissions to install dependencies locally:
- Run the setup script:
./setup_ubuntu.sh
- Authenticate with GCP:
gcloud init
If you cannot install dependencies on your host machine or want a clean, isolated environment for evaluation:
- Spin up the pre-configured Ubuntu VM:
vagrant up
- SSH into the VM:
vagrant ssh
- Inside the VM, initialize GCP:
All necessary tools (Terraform, gcloud CLI) are pre-installed via the Vagrant provisioning script.
gcloud init
Regardless of your setup (Local or Vagrant), follow these steps to deploy:
- GCP Key: Place your Google Cloud service account key as
cloud-1-key.jsonin the project root. - Environment Variables: Create a
.envfile in the root with your Inception project secrets. This file is automatically passed to the VM via metadata.
Run the automated deployment script:
./launch-vm.shOnce the deployment is complete, the launch-vm.sh script will provide the list of external IPs for all created nodes. You can also find them via:
terraform output instance_ips- Wordpress:
http://<IP_NODE_X> - phpMyAdmin:
http://<IP_NODE_X>:8080
This project supports deploying multiple independent servers simultaneously.
To change the number of servers:
- Open
main.tf. - Update the
node_countvariable:variable "node_count" { type = number default = 3 # Change this as needed }
- Run
./launch-vm.shagain. Terraform will provision the additional instances in parallel.
If an application instance is not accessible, you can check its startup script logs by SSHing into the specific VM:
# The launch script provides these commands at the end
gcloud compute ssh cloud-1 --zone=europe-west1-b --command="tail -f /var/log/startup-script.log"
gcloud compute ssh cloud-2 --zone=europe-west1-b --command="tail -f /var/log/startup-script.log"Note
The default zone is europe-west1-b. You can modify this and other variables in main.tf.