WebMagicInformatica
Terraform Associate (004) practice questions

Terraform Associate (004) practice questions: Terraform fundamentals

5 free questions on Terraform fundamentals, 12% of the HashiCorp Terraform Associate exam. Try each one, then open the answer and explanation. None of them are in the free readiness check, so you can still take it fresh.

Question 1

What is the purpose of the .terraform.lock.hcl file, and how should it normally be handled?

  1. A.

    It stores the state of your infrastructure and should be kept out of Git.

  2. B.

    It holds secret variable values and must never be shared.

  3. C.

    It locks the state backend while a plan is running.

  4. D.

    It records the exact provider versions and checksums selected by terraform init, and it should be committed to version control.

Show answer and explanation

Answer: D

The dependency lock file makes later runs select the same provider versions, so teammates and CI behave consistently.

  • It stores the state of your infrastructure and should be kept out of Git.: That is the state file, not the lock file.
  • It holds secret variable values and must never be shared.: It contains provider versions and hashes, not secrets.
  • It locks the state backend while a plan is running.: State locking is handled by the backend.
Question 2

A configuration needs to create a bucket in a second region. Which resource argument selects the aliased provider shown below?

provider "aws" {
  region = "us-east-1"
}

provider "aws" {
  alias  = "west"
  region = "us-west-2"
}
  1. A.

    provider = "west"

  2. B.

    provider = aws.west

  3. C.

    region = aws.west

  4. D.

    alias = aws

Show answer and explanation

Answer: B

The provider meta-argument selects a specific provider configuration using <provider>.<alias>.

  • provider = "west": The value is a reference, not a quoted string.
  • region = aws.west: region is an argument of the provider, not of every resource.
  • alias = aws: alias is set in the provider block, not the resource.
Question 3

In the provider source address hashicorp/aws, what does hashicorp represent?

  1. A.

    The namespace, which is the organisation that publishes the provider.

  2. B.

    The hostname of a private registry.

  3. C.

    The version of the provider.

  4. D.

    The name of the cloud region.

Show answer and explanation

Answer: A

A source address is [hostname/]namespace/type. The namespace identifies the publisher, and aws is the provider type. The hostname defaults to the public registry.

  • The hostname of a private registry.: The hostname, if present, comes first and defaults to registry.terraform.io.
  • The version of the provider.: Versions are set with the version constraint.
  • The name of the cloud region.: Regions are provider arguments.
Question 4

A configuration declares the AWS provider with version = "~> 5.0". terraform init selected 5.40.0 last month and recorded it in .terraform.lock.hcl. A teammate now runs terraform init and version 5.60.0 exists. Which version is installed?

  1. A.

    5.60.0, because init always installs the newest allowed version.

  2. B.

    6.0.0, because the constraint allows major upgrades.

  3. C.

    5.40.0, because the lock file pins the version that was previously selected.

  4. D.

    No provider, because the lock file blocks installation.

Show answer and explanation

Answer: C

The lock file makes terraform init reuse the recorded version while it still satisfies the constraint. terraform init -upgrade is needed to move to a newer version.

  • 5.60.0, because init always installs the newest allowed version.: The lock file prevents that unless -upgrade is used.
  • 6.0.0, because the constraint allows major upgrades.: ~> 5.0 does not allow 6.x.
  • No provider, because the lock file blocks installation.: The recorded version is simply reused.
Question 5

A configuration contains resource "aws_s3_bucket" "logs" { ... } and no explicit provider argument. How does Terraform know which provider manages the resource?

  1. A.

    It always uses the provider listed first in alphabetical order.

  2. B.

    It asks the user interactively at plan time.

  3. C.

    It uses the provider defined in the state file.

  4. D.

    By the resource type prefix: aws_s3_bucket starts with aws, so the aws provider is used.

Show answer and explanation

Answer: D

The first word of the resource type (before the first underscore) maps to the default provider configuration of that name.

  • It always uses the provider listed first in alphabetical order.: Selection is by type prefix.
  • It asks the user interactively at plan time.: Terraform doesn't prompt for this.
  • It uses the provider defined in the state file.: State records providers but the config determines the default.

How ready are you for Terraform Associate (004)?

Take the free readiness check: 15 questions from every exam domain in 20 minutes, with your score per domain.

  • 20 minutes
  • 15 questions
  • Free with an account

More Terraform Associate (004) practice by topic

Back to the Terraform Associate (004) practice test →

Independent practice material written from the official exam guide. Not affiliated with or endorsed by the exam provider.