Learn how to use the alias meta-argument when configuring multiple instances of the same Terraform provider. Understand the purpose and syntax of the alias meta-argument in Terraform provider configurations.
Table of Contents
Question
When using multiple configurations of the same Terraform provider, what meta-argument must be included in any non-default provider configurations?
A. depends_on
B. alias
C. id
D. name
Answer
B. alias
Explanation
When configuring multiple instances of the same Terraform provider, the alias meta-argument must be included in any non-default provider configurations. The alias meta-argument allows you to assign a unique identifier to each provider configuration, enabling Terraform to distinguish between them.
For example, if you have multiple AWS provider configurations with different regions, you would define them as follows:
provider “aws” {
region = “us-west-1”
}
provider “aws” {
alias = “east”
region = “us-east-1”
}
In this case, the default AWS provider configuration has no alias, while the second configuration is assigned the alias “east”. When referring to resources from the non-default provider, you must use the provider argument along with the corresponding alias:
resource “aws_instance” “example” {
provider = aws.east
…
}
Using the alias meta-argument allows Terraform to properly associate resources with their respective provider configurations, ensuring the correct configuration is used for each resource.
HashiCorp Certified: Terraform Associate certification exam practice question and answer (Q&A) dump with detail explanation and reference available free, helpful to pass the HashiCorp Certified: Terraform Associate exam and earn HashiCorp Certified: Terraform Associate certification.