Hey Infra Coders, Letâs Talk Providers!
Welcome back, Infra coders! Youâve already written your first Terraform configuration and created some cool AWS resources like an S3 bucket and an EC2 instance. Now, letâs take it up a notch by exploring providersâthe magic behind Terraformâs ability to work with different cloud platforms. In this article, weâll learn how to manage providers for AWS, Azure, and Google Cloud Platform (GCP) in the same Terraform project. Think of providers as your bridge to different clouds, and weâre about to become bridge-building experts!
Weâll set up a configuration that creates resources across AWS, Azure, and GCP, and Iâll walk you through each step in plain English. Ready? Letâs dive in!

What Are Providers in Terraform?
A provider in Terraform is like a translator that lets Terraform talk to a specific platform, like AWS, Azure, or GCP. Each provider has its own plugin that knows how to create, update, or delete resources on that platform. Terraform supports hundreds of providers, from cloud platforms to tools like Kubernetes or GitHub, but today weâll focus on the big three: AWS, Azure, and GCP.
You can use multiple providers in one Terraform project, which is super powerful for hybrid or multi-cloud setups. For example, you might store files in an AWS S3 bucket, run a virtual machine in Azure, and manage a database in GCPâall with one Terraform configuration.
Step 1: Set Up Your Project
Letâs create a new folder for this project called multi-cloud. Inside it, create a file named main.tf. This will hold our configuration for all three providers. Youâll need accounts for AWS, Azure, and GCP, but if you donât have all of them, you can still follow along and test with the ones you have.
Prerequisites
Before we start, make sure you have:
- Terraform installed (check with
terraform -version). - An AWS account with access keys set up in
~/.aws/credentials. - An Azure account with a service principal (weâll cover how to set this up).
- A GCP account with a service account key (weâll set this up too).
- A text editor like VS Code.
Step 2: Configure the AWS Provider
Letâs start with AWS, since youâre already familiar with it. Add this to your main.tf:
provider "aws" {
region = "us-east-1"
}
This sets up the AWS provider in the us-east-1 region. Your credentials in ~/.aws/credentials will be used automatically. Weâll create an S3 bucket later in the configuration.
Step 3: Configure the Azure Provider
Next, letâs add Azure. To use Terraform with Azure, you need a service principal for authentication. Hereâs how to set it up:
Get Azure Credentials
- Log into the Azure Portal.
- Go to Azure Active Directory â App registrations â New registration.
- Create an app, then note the Application (client) ID and Directory (tenant) ID.
- Create a Client secret under Certificates & secrets and save it.
- Go to Subscriptions, note your Subscription ID, and assign your app Contributor role under Access control (IAM).
Now, add the Azure provider to main.tf:
provider "azurerm" {
features {}
subscription_id = "your-subscription-id"
client_id = "your-client-id"
client_secret = "your-client-secret"
tenant_id = "your-tenant-id"
}
Replace the placeholders with your actual Azure credentials. The features {} block is required for the Azure provider.
Step 4: Configure the GCP Provider
For GCP, you need a service account key. Hereâs how to get it:
Get GCP Credentials
- Go to the GCP Console.
- Navigate to IAM & Admin â Service Accounts â Create Service Account.
- Give it a name, grant Editor role (for this tutorial), and create a JSON key.
- Download the JSON key file and save it securely (e.g.,
gcp-key.json).
Add the GCP provider to main.tf:
provider "google" {
project = "your-gcp-project-id"
region = "us-central1"
credentials = file("gcp-key.json")
}
Replace your-gcp-project-id with your GCP project ID, and make sure gcp-key.json is in your multi-cloud folder.

Step 5: Create Resources Across Providers
Now, letâs create one resource in each cloud to see providers in action:
- AWS: An S3 bucket.
- Azure: A resource group.
- GCP: A Cloud Storage bucket.
Add this to main.tf:
# AWS S3 Bucket
resource "aws_s3_bucket" "my_aws_bucket" {
bucket = "my-unique-bucket-12345"
}
# Azure Resource Group
resource "azurerm_resource_group" "my_azure_group" {
name = "my-terraform-group"
location = "East US"
}
# GCP Cloud Storage Bucket
resource "google_storage_bucket" "my_gcp_bucket" {
name = "my-unique-gcp-bucket-12345"
location = "US"
}
Whatâs happening here?
- AWS: Creates an S3 bucket (use a unique name).
- Azure: Creates a resource group, a container for Azure resources.
- GCP: Creates a Cloud Storage bucket (use a unique name).
Pro Tip
Bucket names in AWS and GCP must be globally unique, so add random numbers or your name to avoid conflicts.
Step 6: Run Your Terraform Commands
Letâs bring this configuration to life. In your multi-cloud folder, run these commands:
Initialize Terraform
terraform init
This downloads plugins for AWS, Azure, and GCP providers.
Preview the Plan
terraform plan
Terraform will show a plan to create one resource in each cloud. Double-check the output.
Apply the Configuration
terraform apply
Type yes to confirm, and Terraform will create the resources. Check your AWS, Azure, and GCP consoles to see the bucket, resource group, and storage bucket.
Step 7: Clean Up
To avoid costs, clean up by running:
terraform destroy
Type yes to delete all resources. Verify in each cloud console that theyâre gone.
Your Complete main.tf File
Hereâs the full main.tf for reference:
provider "aws" {
region = "us-east-1"
}
provider "azurerm" {
features {}
subscription_id = "your-subscription-id"
client_id = "your-client-id"
client_secret = "your-client-secret"
tenant_id = "your-tenant-id"
}
provider "google" {
project = "your-gcp-project-id"
region = "us-central1"
credentials = file("gcp-key.json")
}
resource "aws_s3_bucket" "my_aws_bucket" {
bucket = "my-unique-bucket-12345"
}
resource "azurerm_resource_group" "my_azure_group" {
name = "my-terraform-group"
location = "East US"
}
resource "google_storage_bucket" "my_gcp_bucket" {
name = "my-unique-gcp-bucket-12345"
location = "US"
}
Tips for Managing Multiple Providers
Youâre now managing multiple cloudsânice work! Here are some tips to keep things smooth:
- Secure Credentials: Never hardcode secrets in
.tffiles. Use files like~/.aws/credentialsor environment variables. - Organize Providers: For complex projects, put each providerâs resources in separate
.tffiles (e.g.,aws.tf,azure.tf). - Check Free Tiers: Use free-tier resources to avoid unexpected costs.
- Use Version Control: Save your code in Git to track changes and collaborate.
Whatâs Next?
You just built a multi-cloud setup with Terraformâpretty awesome, right? In the next article, weâll dive into Terraform state management, learning how Terraform keeps track of your infrastructure and how to manage it safely. Keep your multi-cloud folder handy, and letâs keep building, Infra coders!

