HashiCorp Terraform Associate (004) exam dumps

HashiCorp Terraform Associate (004) practice question 34 of 223

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

HashiCorp Terraform Associate (004) Question 34

Single answer2b Describe how Terraform uses providers

A platform team maintains Terraform code that provisions resources in AWS and GitHub for multiple application teams. During a review, a teammate removes the required_providers block because "Terraform can infer providers from the resource types anyway." On the next run in a new CI environment, terraform init installs unexpected provider versions and the plan fails due to behavior changes in one provider release. Which action is the best way to make provider installation predictable across environments while still allowing Terraform to use the correct plugins for AWS and GitHub resources?

  1. A

    Add a required_providers block in the terraform configuration that specifies the source addresses and version constraints for the AWS and GitHub providers, then run terraform init.

  2. B

    Add provider version numbers directly inside each resource block so Terraform can lock the correct plugin version per resource type.

  3. C

    Rely on Terraform to infer the provider from resource prefixes like aws_ and github_; provider inference also guarantees consistent provider versions across machines.

  4. D

    Configure backend settings for the remote state to pin provider plugin versions centrally for all users and CI jobs.

Show answer and explanation

Correct answer: A

Explanation

Terraform uses providers as external plugins to interact with APIs and manage resources and data sources. Resource type names such as aws_instance and github_repository indicate which provider Terraform should use, but best practice is to explicitly declare provider requirements in the terraform block with required_providers. This includes the provider source address and version constraints so terraform init can install appropriate versions consistently. In modern Terraform workflows, this explicit declaration is important for reproducibility and supply-chain clarity, especially when more than one provider offers similarly named resources or when using non-HashiCorp providers. HashiCorp documentation recommends constraining provider versions and allowing terraform init to install the selected provider plugins. Teams commonly combine required_providers with the dependency lock file .terraform.lock.hcl to make installs even more predictable across developer workstations and CI systems.

  • A. Correct.

    Correct. Terraform uses providers as plugins that implement resource types and data sources. The required_providers block is the correct place to declare each provider's source address and version constraints, such as hashicorp/aws or integrations/github. This makes provider selection explicit and predictable during terraform init, especially in new environments. Terraform can often infer that a resource like aws_instance needs the AWS provider, but inference does not replace explicit version constraints for safe, repeatable installation.

  • B. Incorrect.

    Incorrect. Terraform does not support setting provider versions inside individual resource blocks. Resources reference provider types, but provider installation and version selection are configured at the module level in the terraform block using required_providers. Someone might choose this option because resources appear tightly coupled to a provider, but version management is not done there.

  • C. Incorrect.

    Incorrect. Terraform can infer which provider a resource belongs to based on the resource type prefix, which is why aws_instance maps to the AWS provider. However, inference alone does not guarantee consistent versions across environments. Without explicit version constraints, terraform init may select different acceptable versions over time, leading to unexpected behavior changes. This option reflects the common misconception that provider inference also handles version reproducibility.

  • D. Incorrect.

    Incorrect. Backends control where Terraform stores state and, in some cases, how operations are coordinated, but they do not manage provider plugin version selection. Provider requirements are separate from backend configuration. This is a plausible distractor because both backends and providers are initialized during terraform init, but they serve different purposes.

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