0
0
Terraformcloud~30 mins

Provider aliases for multi-region in Terraform - Mini Project: Build & Apply

Choose your learning style9 modes available
Provider aliases for multi-region
📖 Scenario: You are managing cloud resources in two different regions. To keep your infrastructure organized and efficient, you want to use Terraform provider aliases. This helps you deploy resources in multiple regions using the same provider but with different settings.
🎯 Goal: Create a Terraform configuration that uses provider aliases to manage resources in two regions: us-east-1 and us-west-2. You will define the providers with aliases, then create a resource in each region using the correct provider alias.
📋 What You'll Learn
Define the AWS provider for the us-east-1 region with alias useast1.
Define the AWS provider for the us-west-2 region with alias uswest2.
Create an S3 bucket named my-bucket-useast1 in the us-east-1 region using the useast1 provider alias.
Create an S3 bucket named my-bucket-uswest2 in the us-west-2 region using the uswest2 provider alias.
💡 Why This Matters
🌍 Real World
Many companies deploy cloud resources in multiple regions for redundancy, latency, or compliance. Using provider aliases in Terraform helps manage these deployments cleanly.
💼 Career
Cloud engineers and DevOps professionals often need to configure multi-region infrastructure. Knowing provider aliases is essential for scalable and maintainable Terraform code.
Progress0 / 4 steps
1
Define the AWS provider with alias for us-east-1
Write a provider block for AWS with the alias useast1 and set the region to us-east-1.
Terraform
Need a hint?

Use provider "aws" block with alias and region attributes.

2
Define the AWS provider with alias for us-west-2
Add another provider block for AWS with the alias uswest2 and set the region to us-west-2. Keep the previous provider block intact.
Terraform
Need a hint?

Define a second provider block with a different alias and region.

3
Create an S3 bucket in us-east-1 using the useast1 provider alias
Create a resource block for an AWS S3 bucket named my-bucket-useast1. Use the provider alias useast1 by specifying provider = aws.useast1.
Terraform
Need a hint?

Use resource "aws_s3_bucket" with provider = aws.useast1 and set the bucket name.

4
Create an S3 bucket in us-west-2 using the uswest2 provider alias
Add a resource block for an AWS S3 bucket named my-bucket-uswest2. Use the provider alias uswest2 by specifying provider = aws.uswest2. Keep all previous code intact.
Terraform
Need a hint?

Add another aws_s3_bucket resource with the correct provider alias and bucket name.