TA-002-P · Question #157
John wants to use two different regions to deploy two different EC2 instances. He has specified two provider blocks in his providers.tf file. provider "aws" { region = "us-east-1" } provider "aws" {…
The correct answer is B. Use alias for region = "us-west-2". Terraform requires the alias meta-argument to distinguish between multiple provider blocks of the same provider type in a single configuration.
Question
John wants to use two different regions to deploy two different EC2 instances. He has specified two provider blocks in his providers.tf file. provider "aws" { region = "us-east-1" } provider "aws" { region = "us-west-2" } When he run terraform plan he encountered an error. How to fix this?
Options
- AUse another provider version
- BUse alias for region = "us-west-2"
- CUse default keyword with region = "us-east-1"
- DIt can not be fixed
How the community answered
(37 responses)- A5% (2)
- B78% (29)
- C3% (1)
- D14% (5)
Why each option
Terraform requires the alias meta-argument to distinguish between multiple provider blocks of the same provider type in a single configuration.
Changing the provider version does not resolve the issue because the error is caused by having two unnamed provider blocks of the same type, not a version conflict.
Adding alias = "west" (or any label) to the second aws provider block makes it a non-default named provider configuration that can be referenced explicitly via provider = aws.west in resource blocks. Without an alias, Terraform cannot differentiate the two aws provider blocks and throws a duplicate provider error during plan.
Terraform does not support a default keyword in provider configuration - the default provider is implicitly the provider block that lacks an alias attribute.
The error is entirely fixable by adding an alias to the second provider block, making this answer factually incorrect.
Concept tested: Terraform provider alias for multiple region configurations
Source: https://developer.hashicorp.com/terraform/language/providers/configuration#alias-multiple-provider-configurations
Topics
Community Discussion
No community discussion yet for this question.