Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Terraform — Multiple Providers

Companion lab for the Medium article Terraform — Using Multiple Providers. Part of my Terraform fundamentals series — more on Medium.


What you'll learn

How to deploy resources to multiple AWS regions (or multiple AWS accounts) from a single Terraform project using provider aliases — the canonical pattern for cross-region and multi-account infrastructure.

Architecture

┌──────────────────┐       ┌──────────────────────────────────┐
│   Terraform      │       │   AWS                            │
│                  │       │                                  │
│   provider.aws   │ ────► │   S3 bucket · us-east-1 (VA)     │
│                  │       │                                  │
│   provider.aws   │ ────► │   S3 bucket · eu-west-3 (Paris)  │
│   .paris (alias) │       │                                  │
└──────────────────┘       └──────────────────────────────────┘

One codebase, two provider instances, two regions.

What's inside

File Purpose
provider.tf Declares two AWS provider instances: default (us-east-1) and paris alias (eu-west-3)
variables.tf Defines bucket_virginia and bucket_paris input variables
main.tf Creates S3 buckets — one in each region, using provider = aws.paris on the second
output.tf Outputs the regional domain names of both buckets
backend.tf Configures local state backend

Prerequisites

  • Terraform ≥ 1.5
  • AWS CLI configured (aws configure) with a default profile that has access to both regions
  • Globally unique S3 bucket names — set bucket_virginia and bucket_paris via terraform.tfvars or -var (the defaults will collide)

Quick start

# Initialize (downloads the AWS provider once, used for both aliases)
terraform init

# Preview — you should see 2 S3 buckets, one per region
terraform plan \
  -var="bucket_virginia=my-unique-va-bucket-2026" \
  -var="bucket_paris=my-unique-paris-bucket-2026"

# Apply
terraform apply \
  -var="bucket_virginia=my-unique-va-bucket-2026" \
  -var="bucket_paris=my-unique-paris-bucket-2026"

# Inspect the outputs
terraform output

Expected output: two s3.<region>.amazonaws.com domain names, one for Virginia and one for Paris.

Cleanup

terraform destroy \
  -var="bucket_virginia=my-unique-va-bucket-2026" \
  -var="bucket_paris=my-unique-paris-bucket-2026"

Key concepts

  • Provider aliasesalias = "paris" creates a second provider instance you can reference as aws.paris
  • provider = resource argument — attach a resource to a specific provider instance (provider = aws.paris)
  • Single terraform init — downloads the provider plugin once even for multiple instances
  • Multi-region (and by extension, multi-account) pattern — swap regions for account credentials to manage infra across AWS accounts

When you'd use this in production

  • Cross-region DR — primary in us-east-1, disaster recovery in another region
  • Multi-account organization — one Terraform root module managing infra across accounts via assume-role
  • Mixing cloud providersprovider.aws + provider.gcp + provider.azurerm all in one module

Series

Part of my Terraform fundamentals series:

All articles on Medium.

About

Terraform lab using multiple AWS providers across regions. Companion to a Medium article.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages