HashiCorp Terraform Associate (004) exam dumps

HashiCorp Terraform Associate (004) practice question 32 of 223

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

HashiCorp Terraform Associate (004) Question 32

Single answer2b Describe how Terraform uses providers

A team is standardizing Terraform configurations for AWS. In one project, they need to create an S3 bucket in us-east-1 and a DynamoDB table in us-west-2 from the same root module. A junior engineer proposes defining only one default AWS provider and setting region values directly inside each resource block. You review the configuration and want to explain how Terraform actually uses providers in this scenario. Which approach is correct?

  1. A

    Define two AWS provider configurations, using an alias for the second region, and assign resources to the appropriate provider configuration with the provider meta-argument.

  2. B

    Keep a single default AWS provider configuration and set a region argument on each aws_s3_bucket and aws_dynamodb_table resource to override the provider region per resource.

  3. C

    Create separate required_providers entries for each AWS region so Terraform installs one provider plugin per region automatically.

  4. D

    Use Terraform workspaces to switch the AWS provider region between resources within the same apply operation.

Show answer and explanation

Correct answer: A

Explanation

Terraform uses providers as plugins that define resource types and communicate with external services through their APIs. In practice, the required_providers block tells Terraform which provider to install and which version constraints apply, while provider blocks configure how that provider should connect and behave, such as AWS region, credentials, or endpoints. When a configuration must manage resources in multiple regions or accounts for the same provider, Terraform supports multiple provider configurations in the same root module by using aliases and the provider meta-argument on resources or modules. This is a core pattern described in HashiCorp Terraform documentation for provider configuration and provider aliases. The key exam takeaway is that providers are the mechanism Terraform uses to map resource blocks to real infrastructure APIs, and provider configuration, not resource-local arguments or workspaces, controls details like region.

  • A. Correct.

    Correct. Terraform uses providers to interact with external APIs, and a provider configuration supplies settings such as region and credentials. When you need multiple configurations of the same provider in one root module, you define additional provider blocks with aliases, for example provider "aws" { region = "us-east-1" } and provider "aws" { alias = "west" region = "us-west-2" }. Resources can then select the non-default configuration with the provider meta-argument, such as provider = aws.west. This is the supported way to manage resources in multiple AWS regions from the same configuration.

  • B. Incorrect.

    Incorrect. AWS region is not generally configured on individual aws_* resource blocks like aws_s3_bucket or aws_dynamodb_table. Terraform resources use the provider configuration assigned to them. A common misconception is that resource blocks override provider-level settings directly, but for AWS region selection Terraform expects you to use provider configurations, not per-resource region arguments.

  • C. Incorrect.

    Incorrect. The required_providers block declares the provider source and version constraints, not separate regional instances. Terraform installs the provider plugin based on provider requirements, but regions are defined in provider configuration blocks. Another common misconception is confusing provider installation and version selection with runtime configuration such as region or credentials.

  • D. Incorrect.

    Incorrect. Workspaces let you manage multiple state instances for the same configuration, but they do not allow different resources in the same plan or apply to use different regions automatically. Workspaces are not a substitute for multiple provider configurations. In this scenario, both regions must be available in the same run, which requires aliased provider configurations.

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