Terraform Advanced — GCP & Azure Alongside AWS

less than 1 minute read

Real-world patterns for running workloads across multiple clouds.


GCP Provider Authentication

# Option 1: Service account key (not recommended for production)
export GOOGLE_CREDENTIALS="/path/to/sa-key.json"

# Option 2: Application Default Credentials
gcloud auth application-default login

# Option 3: Workload Identity Federation (recommended for CI/CD)
provider "google" {
  project = var.gcp_project_id
  region  = var.gcp_region
}

resource "google_storage_bucket" "data" {
  name     = "my-data-lake"
  location = "US"
}

Azure Provider Authentication

# Option 1: Azure CLI
az login

# Option 2: Service Principal
export ARM_CLIENT_ID="..."
export ARM_CLIENT_SECRET="..."
export ARM_TENANT_ID="..."
export ARM_SUBSCRIPTION_ID="..."
provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "main" {
  name     = "rg-myapp"
  location = "East US"
}

Repo Structure for Multi-Cloud

infra/
├── aws/
│   ├── networking/
│   ├── compute/
│   └── backend.tf
├── gcp/
│   ├── storage/
│   └── backend.tf
├── azure/
│   ├── identity/
│   └── backend.tf
└── shared/
    └── dns/           # Cross-cloud DNS
        └── main.tf    # Uses all three providers

What’s Next?

Design modules that work across clouds.

← Cross-Provider Dependencies Multi-Cloud Module Design →

Updated: