0
0
Terraformcloud~20 mins

Multiple provider configurations in Terraform - Practice Problems & Coding Challenges

Choose your learning style9 modes available
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.