HashiCorp Terraform Associate (004) exam dumps

HashiCorp Terraform Associate (004) practice question 31 of 223

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

HashiCorp Terraform Associate (004) Question 31

Single answer2b Describe how Terraform uses providers

A platform team is standardizing Terraform configurations across several projects. One application stack must create an AWS VPC and also create DNS records in Cloudflare. A developer writes resource blocks for both platforms but forgets to declare any provider requirements. On a new workstation, they run terraform init and want Terraform to install the correct plugins and understand which API each resource belongs to. Which configuration change best addresses this requirement?

  1. A

    Add a terraform block with a required_providers section that declares the AWS and Cloudflare providers and their source addresses, then configure each provider as needed.

  2. B

    Add provider names directly inside each resource block so Terraform can infer and download the matching provider without any provider declaration.

  3. C

    Define the providers only in the backend configuration, because backends are responsible for installing external plugins before planning.

  4. D

    Set environment variables for AWS and Cloudflare credentials only, because Terraform uses credentials to automatically determine provider source and version.

Show answer and explanation

Correct answer: A

Explanation

Providers are Terraform plugins that define resource types and data sources for external platforms such as AWS and Cloudflare. In real-world configurations, Terraform should explicitly declare provider requirements in the terraform.required_providers block so terraform init can download the correct provider plugins from the correct source addresses and honor version constraints. Provider configuration itself belongs in provider blocks, while credentials may come from arguments or environment variables depending on provider support. This question also tests a common exam distinction: providers are not the same as backends. HashiCorp documentation emphasizes using required_providers to specify provider source and version requirements, and terraform init uses that information to install the provider plugins needed by the configuration.

  • A. Correct.

    Correct. Terraform uses providers as plugins to interact with external APIs. Declaring providers in the terraform block under required_providers tells Terraform which providers are required, where to download them from, and optionally which versions are acceptable. Separate provider blocks are then used for provider-specific configuration such as region, tokens, or aliases. This is the recommended and modern approach, especially when using providers from the Terraform Registry such as hashicorp/aws or cloudflare/cloudflare.

  • B. Incorrect.

    Incorrect. Resource blocks reference a resource type such as aws_vpc or cloudflare_record, and Terraform can infer the provider local name from the resource type prefix, but that does not replace declaring provider requirements. Without required_providers, Terraform may not know the intended source address for non-HashiCorp providers, and relying on inference is not the best practice expected for portable configurations.

  • C. Incorrect.

    Incorrect. Backend configuration is for storing Terraform state and handling operations such as remote state locking, not for defining infrastructure providers. Backends and providers are different concepts: backends manage state, while providers expose resource types and data sources for external services.

  • D. Incorrect.

    Incorrect. Credentials help authenticate provider API calls after the provider is installed and configured, but they do not define which provider plugin Terraform should download or which version/source to use. Provider installation is driven by configuration, not by environment variables alone.

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