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
Recall & Review
beginner
What is the purpose of using multiple provider configurations in Terraform?
Multiple provider configurations allow Terraform to manage resources across different accounts, regions, or cloud providers within the same configuration.
Click to reveal answer
beginner
How do you define an additional provider configuration in Terraform?
You define an additional provider by giving it an alias inside the provider block, for example:
provider "aws" { alias = "west" region = "us-west-2" }
Click to reveal answer
beginner
How do you specify which provider configuration a resource should use?
You specify the provider by using the 'provider' argument inside the resource block, referencing the provider alias, for example:
Can you use multiple providers of the same type in one Terraform configuration?
Yes, by using aliases you can configure multiple providers of the same type to manage resources in different regions or accounts.
Click to reveal answer
intermediate
What happens if you do not specify a provider alias for a resource when multiple providers are configured?
Terraform uses the default provider configuration without an alias. If multiple providers exist, resources without a specified provider use the default one.
Click to reveal answer
How do you create a second AWS provider configuration for the us-east-1 region?
Aprovider "aws-east" { region = "us-east-1" }
Bprovider "aws" { region = "us-east-1" }
Cprovider "aws" { alias = "east" region = "us-east-1" }
Dresource "aws" { alias = "east" region = "us-east-1" }
✗ Incorrect
You create a second provider by adding an alias inside the provider block with the desired region.
How do you tell a resource to use the aliased provider 'aws.west'?
Aalias = aws.west
Bprovider = "aws.west"
Cprovider = aws-west
Dprovider = aws.west
✗ Incorrect
Inside the resource block, you set provider = aws.west without quotes to specify the aliased provider.
What is the default provider configuration called in Terraform?
Adefault
Bno alias
Cunnamed
Dmain
✗ Incorrect
The default provider configuration is the one without an alias.
Can you use multiple providers of different cloud types in one Terraform configuration?
AYes, Terraform supports multiple providers including different clouds.
BNo, only one cloud provider per configuration is allowed.
COnly if they share the same API version.
DOnly if they are from the same vendor.
✗ Incorrect
Terraform supports multiple providers from different cloud vendors in the same configuration.
What is the benefit of using multiple provider configurations?
AManage resources across multiple accounts or regions easily.
BReduce Terraform execution time.
CAutomatically backup state files.
DEncrypt resource data.
✗ Incorrect
Multiple providers let you manage resources in different accounts or regions within one Terraform setup.
Explain how to configure and use multiple AWS providers in Terraform.
Think about how you tell Terraform which AWS region or account to use for each resource.
You got /3 concepts.
Describe what happens if you have multiple provider configurations but a resource does not specify which one to use.
Consider the provider without an alias as the fallback.
You got /3 concepts.
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
Step 1: Understand provider role
Providers in Terraform define where resources are created, such as cloud accounts or regions.
Step 2: Purpose of multiple providers
Using multiple providers allows managing resources across different accounts or regions simultaneously.
Final Answer:
To manage resources in different cloud accounts or regions -> Option C
bucket2 uses provider = aws.east, which refers to the aliased provider with region us-east-1.
Step 2: Confirm region of aliased provider
The alias "east" is set with region = "us-east-1".
Final Answer:
us-east-1 -> Option D
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
Step 1: Check provider aliases defined
Only alias 'east' is defined; no alias 'west' exists.
Step 2: Identify usage of undefined alias
Resource 'example2' uses provider = aws.west, which is undefined and causes an error.
Final Answer:
The alias 'west' is not defined for any provider -> Option B
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
Step 1: Understand provider alias usage
To deploy to Account B, the resource must use the provider with alias 'east'.
Step 2: Assign provider alias to resource
Setting provider = aws.east in the resource block directs Terraform to use that provider configuration.
Final Answer:
Set provider = aws.east in the S3 bucket resource block -> Option A
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