Bird
Raised Fist0
Terraformcloud~20 mins

Multiple provider configurations in Terraform - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Multiple Provider Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Configuration
intermediate
2:00remaining
Identify the correct provider alias usage

You have two AWS providers configured with aliases us_east and us_west. Which resource block correctly uses the us_west provider?

Terraform
provider "aws" {
  region = "us-east-1"
  alias  = "us_east"
}

provider "aws" {
  region = "us-west-2"
  alias  = "us_west"
}

resource "aws_s3_bucket" "example" {
  bucket = "my-bucket"
  provider = aws.us_west
}
A
resource "aws_s3_bucket" "example" {
  bucket = "my-bucket"
  provider = aws.us_east
}
B
resource "aws_s3_bucket" "example" {
  bucket = "my-bucket"
  provider = aws.us_west
}
C
resource "aws_s3_bucket" "example" {
  bucket = "my-bucket"
  provider = aws
}
D
resource "aws_s3_bucket" "example" {
  bucket = "my-bucket"
  provider = aws.west
}
Attempts:
2 left
💡 Hint

Use the exact alias name defined in the provider block.

❓ Architecture
intermediate
2:00remaining
Choosing provider configuration for multi-region deployment

You want to deploy resources in two AWS regions: us-east-1 and eu-west-1. Which provider configuration setup is correct to support this?

A
provider "aws" {
  region = "us-east-1"
}

provider "aws" {
  region = "eu-west-1"
  alias  = "europe"
}
B
provider "aws" {
  region = "us-east-1"
  alias  = "east"
}

provider "aws" {
  region = "eu-west-1"
  alias  = "west"
}
C
provider "aws" {
  region = "us-east-1"
}

provider "aws" {
  region = "eu-west-1"
}
D
provider "aws" {
  region = "us-east-1"
  alias  = "us-east"
}

provider "aws" {
  region = "eu-west-1"
  alias  = "eu-west"
}
Attempts:
2 left
💡 Hint

Only one provider block can be default (no alias). Others must have aliases.

❓ service_behavior
advanced
2:00remaining
Effect of missing provider alias in resource

Given two AWS providers configured with aliases, what happens if a resource specifies a provider without alias but multiple providers exist?

Terraform
provider "aws" {
  region = "us-east-1"
  alias  = "east"
}

provider "aws" {
  region = "us-west-2"
  alias  = "west"
}

resource "aws_instance" "example" {
  ami           = "ami-123456"
  instance_type = "t2.micro"
  provider      = aws
}
ATerraform randomly picks one of the aliased providers.
BTerraform uses the provider with alias 'east' by default.
CTerraform uses the provider with alias 'west' by default.
DTerraform raises an error because no default provider is configured.
Attempts:
2 left
💡 Hint

Terraform requires a default provider if no alias is specified in resource.

❓ security
advanced
2:00remaining
Security implications of multiple provider credentials

You configure multiple providers with different credentials for different AWS accounts. What is a key security best practice?

AShare credentials between providers to reduce complexity.
BStore all credentials in the same Terraform configuration file in plain text.
CUse environment variables or secret management tools to inject credentials securely.
DHardcode credentials in resource blocks for clarity.
Attempts:
2 left
💡 Hint

Think about how to keep credentials safe and avoid exposure.

🧠 Conceptual
expert
3:00remaining
Understanding provider inheritance in modules

You have a root module with two AWS providers configured: one default and one with alias europe. You call a child module that creates an S3 bucket. The child module does not specify a provider. Which provider will the child module use?

Terraform
provider "aws" {
  region = "us-east-1"
}

provider "aws" {
  region = "eu-west-1"
  alias  = "europe"
}

module "storage" {
  source = "./modules/s3"
}
AThe child module uses the default provider (us-east-1).
BThe child module uses the aliased provider (europe).
CTerraform raises an error because the child module does not specify a provider.
DThe child module randomly picks one of the providers.
Attempts:
2 left
💡 Hint

Modules inherit the default provider unless explicitly passed an alias.

Practice

(1/5)
1. What is the main purpose of using multiple provider configurations in Terraform?
easy
A. To reduce the size of Terraform state files
B. To speed up Terraform plan execution
C. To manage resources in different cloud accounts or regions
D. To automatically backup Terraform configurations

Solution

  1. Step 1: Understand provider role

    Providers in Terraform define where resources are created, such as cloud accounts or regions.
  2. Step 2: Purpose of multiple providers

    Using multiple providers allows managing resources across different accounts or regions simultaneously.
  3. Final Answer:

    To manage resources in different cloud accounts or regions -> Option C
  4. Quick Check:

    Multiple providers = manage multiple accounts/regions [OK]
Hint: Multiple providers = multiple accounts or regions [OK]
Common Mistakes:
  • Thinking multiple providers speed up execution
  • Confusing providers with state file management
  • Assuming providers handle backups
2. Which Terraform syntax correctly defines a second AWS provider with an alias named east?
easy
A. provider "aws" { alias = "east" region = "us-east-1" }
B. provider "aws" { region = "us-east-1", alias = "east" }
C. provider "aws" { region = "us-east-1" } alias = "east"
D. provider "aws" alias = "east" { region = "us-east-1" }

Solution

  1. Step 1: Check provider block syntax

    The alias attribute must be inside the provider block, before or after region.
  2. Step 2: Validate provider "aws" { alias = "east" region = "us-east-1" }

    provider "aws" { alias = "east" region = "us-east-1" } correctly places alias = "east" inside the provider block with region.
  3. Final Answer:

    provider "aws" { alias = "east" region = "us-east-1" } -> Option A
  4. Quick Check:

    Alias inside provider block = correct syntax [OK]
Hint: Alias must be inside provider block braces [OK]
Common Mistakes:
  • Placing alias outside provider block
  • Using alias without quotes
  • Misordering block elements causing syntax errors
3. Given this Terraform snippet:
provider "aws" {
  region = "us-west-2"
}

provider "aws" {
  alias  = "east"
  region = "us-east-1"
}

resource "aws_s3_bucket" "bucket1" {
  bucket = "west-bucket"
}

resource "aws_s3_bucket" "bucket2" {
  provider = aws.east
  bucket   = "east-bucket"
}

Which region will bucket2 be created in?
medium
A. us-west-2
B. us-east-2
C. us-west-1
D. us-east-1

Solution

  1. Step 1: Identify provider for bucket2

    bucket2 uses provider = aws.east, which refers to the aliased provider with region us-east-1.
  2. Step 2: Confirm region of aliased provider

    The alias "east" is set with region = "us-east-1".
  3. Final Answer:

    us-east-1 -> Option D
  4. Quick Check:

    Aliased provider region = us-east-1 [OK]
Hint: Resource uses aliased provider region [OK]
Common Mistakes:
  • Assuming default provider region applies
  • Ignoring provider alias in resource
  • Confusing region names
4. What is wrong with this Terraform configuration snippet?
provider "aws" {
  region = "us-west-2"
}

provider "aws" {
  alias = "east"
  region = "us-east-1"
}

resource "aws_instance" "example" {
  provider = aws.east
  ami      = "ami-123456"
  instance_type = "t2.micro"
}

resource "aws_instance" "example2" {
  provider = aws.west
  ami      = "ami-654321"
  instance_type = "t2.micro"
}
medium
A. The provider alias 'east' is missing region
B. The alias 'west' is not defined for any provider
C. The resource 'example' is missing provider assignment
D. The provider block syntax is invalid

Solution

  1. Step 1: Check provider aliases defined

    Only alias 'east' is defined; no alias 'west' exists.
  2. Step 2: Identify usage of undefined alias

    Resource 'example2' uses provider = aws.west, which is undefined and causes an error.
  3. Final Answer:

    The alias 'west' is not defined for any provider -> Option B
  4. Quick Check:

    Undefined alias causes error [OK]
Hint: Check all provider aliases are defined before use [OK]
Common Mistakes:
  • Assuming default provider applies to aliased names
  • Missing alias attribute in provider block
  • Incorrect provider block syntax
5. You want to deploy resources to two AWS accounts: Account A in us-west-2 and Account B in us-east-1. You have two provider blocks with aliases west and east. How do you ensure that an S3 bucket resource is created in Account B using Terraform?
hard
A. Set provider = aws.east in the S3 bucket resource block
B. Set region = "us-east-1" inside the S3 bucket resource block
C. Use alias = "east" inside the S3 bucket resource block
D. Create a new provider block inside the S3 bucket resource

Solution

  1. Step 1: Understand provider alias usage

    To deploy to Account B, the resource must use the provider with alias 'east'.
  2. Step 2: Assign provider alias to resource

    Setting provider = aws.east in the resource block directs Terraform to use that provider configuration.
  3. Final Answer:

    Set provider = aws.east in the S3 bucket resource block -> Option A
  4. Quick Check:

    Resource provider = aliased provider [OK]
Hint: Assign provider alias in resource block to target account [OK]
Common Mistakes:
  • Trying to set region inside resource instead of provider
  • Using alias attribute inside resource block incorrectly
  • Defining provider block inside resource block