This task demonstrates how to deploy and manage cloud workloads across AWS, Azure, and GCP using a single Terraform configuration. The project includes provisioning compute instances, storage, networking, and security policies in each cloud while ensuring consistency and automation using Terraform.
+---------------------------------+ | GitHub/Jenkins | +---------------------------------+ | --------------------------------------------------- | | | AWS VPC Azure VNet GCP VPC (EC2, S3) (VM, Blob) (GCE, GCS) | | | Security Groups NSG & RBAC Firewall Rules
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add - sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main" sudo apt-get update && sudo apt-get install terraform terraform -version
terraform { required_providers { aws = { source = "hashicorp/aws" } azurerm = { source = "hashicorp/azurerm" } google = { source = "hashicorp/google" } } }
Use S3/DynamoDB, Azure Blob Storage, or GCP Cloud Storage for state management.
terraform { backend "s3" { bucket = "terraform-state-multicloud" key = "global/terraform.tfstate" region = "us-east-1" encrypt = true dynamodb_table = "terraform-lock" } }
terraform { backend "azurerm" { resource_group_name = "terraform-backend" storage_account_name = "tfstateaccount" container_name = "tfstate" key = "terraform.tfstate" } }
provider "aws" { region = "us-east-1" } resource "aws_instance" "web" { ami = "ami-12345678" instance_type = "t2.micro" tags = { Name = "AWS-WebServer" } }
provider "azurerm" { features {} } resource "azurerm_virtual_machine" "web" { name = "AzureVM" location = "East US" resource_group_name = "terraform-rg" vm_size = "Standard_B1s" }
provider "google" { project = "my-gcp-project" region = "us-central1" } resource "google_compute_instance" "web" { name = "GCP-WebServer" machine_type = "e2-medium" zone = "us-central1-a" }
resource "aws_vpc" "main" { cidr_block = "10.0.0.0/16" } resource "aws_security_group" "allow_ssh" { vpc_id = aws_vpc.main.id ingress { from_port = 22 to_port = 22 protocol = "tcp" cidr_blocks = ["0.0.0.0/0"] } }
resource "azurerm_network_security_group" "nsg" { name = "azure-nsg" location = "East US" resource_group_name = "terraform-rg" }
resource "google_compute_firewall" "allow-ssh" { name = "allow-ssh" network = "default" allow { protocol = "tcp" ports = ["22"] } }
terraform init
terraform validate
terraform plan
terraform apply -auto-approve
Using GitHub Actions for automation.
name: Terraform Multi-Cloud Deployment on: push: branches: - main jobs: deploy: runs-on: ubuntu-latest steps: - name: Checkout Code uses: actions/checkout@v2 - name: Setup Terraform uses: hashicorp/setup-terraform@v1 - name: Terraform Init run: terraform init - name: Terraform Plan run: terraform plan - name: Terraform Apply run: terraform apply -auto-approve
This project provides a production-ready Terraform setup for deploying and managing workloads across AWS, Azure, and GCP with a unified IaC approach. It ensures scalability, security, and automation, making multi-cloud management seamless. 🚀