HashiCorp Terraform Associate (004) exam dumps

HashiCorp Terraform Associate (004) practice question 39 of 223

Terraform Associate 004. Associate level, HashiCorp. Free question with the correct answer and a full explanation.

HashiCorp Terraform Associate (004) Question 39

Single answer2c Write Terraform configuration using multiple providers

A platform team manages AWS infrastructure in two regions from a single Terraform root module. They need to create a VPC in us-east-1 and an S3 bucket in us-west-2 using the same AWS provider plugin. They also want the configuration to be explicit so future resources do not accidentally use the wrong region. Which configuration approach best meets these requirements?

  1. A

    Define two aws provider configurations, give one an alias such as west, and set the region in each provider block. Then assign provider = aws.west only on the resources that must use us-west-2.

  2. B

    Define one aws provider block without an alias and set region = "us-east-1". On the S3 bucket resource, add region = "us-west-2" to override the provider region for that resource.

  3. C

    Define two terraform blocks, one for each region, and place required_providers for aws separately in each terraform block so Terraform selects the correct region automatically per resource.

  4. D

    Define two aws provider configurations with aliases east and west, and require every resource to set provider = aws.east or provider = aws.west explicitly.

Show answer and explanation

Correct answer: A

Explanation

Terraform distinguishes between provider requirements and provider configurations. The terraform.required_providers block declares which provider plugin is needed, while provider blocks configure how that provider connects and behaves, such as setting AWS regions. When you need to use the same provider plugin multiple times with different settings, Terraform supports multiple provider configurations through aliases. In this scenario, the best practice is to configure a default aws provider for the primary region, such as us-east-1, and an aliased provider like aws.west for us-west-2. Then only the resources that belong in the secondary region need provider = aws.west. This makes the configuration explicit and reduces the chance of creating resources in the wrong region. HashiCorp documentation on provider configuration and provider aliases covers this pattern, including the use of the provider meta-argument on resources and modules.

  • A. Correct.

    Correct. Terraform supports multiple configurations of the same provider by using provider aliases. A common and recommended pattern is to keep one default provider configuration for the most common region and add an aliased provider for the secondary region. Resources that should use the non-default configuration specify the provider meta-argument, such as provider = aws.west. This is explicit, valid Terraform syntax, and a practical way to avoid unintended regional placement while still minimizing repetition.

  • B. Incorrect.

    Incorrect. Terraform resources generally do not support a generic region argument to override the provider's configured region. Region is typically configured in the provider, not as a universal resource-level setting. Someone might choose this because some cloud consoles or CLIs let you specify region per command, but Terraform uses provider configurations for this purpose.

  • C. Incorrect.

    Incorrect. The terraform block is not used to create separate runtime provider configurations by region. The required_providers setting declares provider source addresses and version constraints, not region-specific instances. Terraform will not automatically select regions per resource from multiple terraform blocks. This reflects a misunderstanding of the difference between provider requirements and provider configurations.

  • D. Incorrect.

    Incorrect. This can work technically if both aliased provider configurations are defined and every resource references one explicitly, but it is not the best answer for the stated requirement. If all provider configurations are aliased, Terraform has no default configuration, which can make the configuration more verbose than necessary. The scenario asks for the approach that best meets the goal, and using one default plus one alias is the cleaner and more common pattern when one region is primary.

Timed practice exam

Take a HashiCorp Terraform Associate (004) practice test under exam conditions

70 questions in 60 minutes, drawn from this bank, with a score report and a per-question review when you finish.

Start timed exam