🎓 A1Learner
🔍
0 of 50 lessons completed

A Second Cloud: Azure and GCP

A second cloud is the same Terraform shape with a different provider. The blocks change, but the workflow stays the same.

Azure: one resource group

The azurerm provider talks to Azure. A resource group holds the resources that belong together.

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~> 4.0"
    }
  }
}

provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "example" {
  name     = "example-resources"
  location = "UK South"
}

GCP: one bucket

The google provider talks to GCP. A storage bucket holds objects, much like an S3 bucket.

terraform {
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "~> 6.0"
    }
  }
}

provider "google" {
  project = "my-project-id"
  region  = "europe-west2"
}

resource "google_storage_bucket" "example" {
  name     = "my-example-bucket"
  location = "EU"
}

The same workflow

The commands are the same on every cloud. Sign in first, with az login for Azure or gcloud auth for GCP.

terraform init
terraform plan
terraform apply

Example

# Azure: sign in first with: az login
# main-azure.tf
terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~> 4.0"
    }
  }
}

provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "example" {
  name     = "example-resources"
  location = "UK South"
}

# GCP: sign in first with: gcloud auth application-default login
# main-gcp.tf
terraform {
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "~> 6.0"
    }
  }
}

provider "google" {
  project = "my-project-id"
  region  = "europe-west2"
}

resource "google_storage_bucket" "example" {
  name     = "my-example-bucket"
  location = "EU"
}

# terraform init
# terraform plan
# terraform apply
# terraform destroy

Key points

  • Terraform does not care which cloud a resource lives on.
  • Each cloud has its own provider and its own resource names.
  • Azure groups resources in a resource group.
  • GCP stores objects in a storage bucket.
  • The workflow is still init, plan, and apply.
  • This lesson was NOT run against a live Azure or GCP account.

Two providers, two clouds, one workflow. The Azure file creates a resource group and the GCP file creates a bucket. Neither file was run against a live account, so no output is shown here.

Note

A real Azure or GCP account is needed to follow along.

Try it Yourself

Edit the code, then press Run.

Running is simulated · Rust Playground

Exercise

What stays the same when you move from AWS to Azure or GCP?