Terraform Associate · Domain 2 of 8 · 12% of the exam

Terraform Associate Domain 2: Terraform Fundamentals

25 free practice questions for Terraform Fundamentals in the HashiCorp Certified: Terraform Associate (004) exam. Try each question first, then open "Show answer" for the correct option and explanation.

Terraform Fundamentals practice questions

  1. Question 1. Which block declares the providers a configuration needs and where to get them?

    1. required_providers inside the terraform block
    2. provider_requirements inside each provider block
    3. A top-level providers block
    4. plugins inside the backend block
    Show answer

    Answer: A. required_providers inside the terraform block

    Each entry sets a local name, a source address such as hashicorp/aws, and a version constraint.

  2. Question 2. What does the provider source address hashicorp/aws mean?

    1. The aws provider bundled inside the Terraform binary
    2. Namespace hashicorp, type aws, from the public Terraform Registry
    3. A Git repository that must be cloned manually
    4. An AWS account named hashicorp
    Show answer

    Answer: B. Namespace hashicorp, type aws, from the public Terraform Registry

    The full form is registry.terraform.io/hashicorp/aws. The hostname is optional when it's the public registry.

  3. Question 3. Which versions does the constraint version = "~> 5.4" allow?

    1. >= 5.4.0 and < 5.5.0
    2. Exactly 5.4.0
    3. Any version from 5.4 upward, including 6.x
    4. >= 5.4 and < 6.0
    Show answer

    Answer: D. >= 5.4 and < 6.0

    The ~> operator allows only the rightmost given component to increase. With two components, minor versions can rise but not the major version.

  4. Question 4. Which versions does the constraint version = "~> 5.4.1" allow?

    1. >= 5.4.1 and < 5.5.0
    2. >= 5.4.1 and < 6.0.0
    3. Exactly 5.4.1
    4. Any version below 5.4.1
    Show answer

    Answer: A. >= 5.4.1 and < 5.5.0

    With three components, only the patch version can rise, so 5.4.2 is allowed but 5.5.0 isn't.

  5. Question 5. What does the .terraform.lock.hcl file record?

    1. The current state of every resource
    2. Which user holds the state lock
    3. Selected provider versions and their checksums
    4. The order resources were created in
    Show answer

    Answer: C. Selected provider versions and their checksums

    terraform init writes the chosen versions and hashes, and later inits reuse them so every run uses the same provider builds.

  6. Question 6. Should the dependency lock file .terraform.lock.hcl be committed to version control?

    1. No, it contains secrets
    2. Yes, so everyone and CI use the same provider versions
    3. No, Terraform rebuilds it on every plan
    4. Only when using HCP Terraform
    Show answer

    Answer: B. Yes, so everyone and CI use the same provider versions

    Committing it keeps provider selections consistent. The .terraform directory, by contrast, should not be committed.

  7. Question 7. Which command upgrades providers to the newest versions their constraints allow, updating the lock file?

    1. terraform get -update
    2. terraform providers upgrade
    3. terraform apply -upgrade
    4. terraform init -upgrade
    Show answer

    Answer: D. terraform init -upgrade

    Without -upgrade, init keeps the versions recorded in the lock file.

  8. Question 8. By default, where does terraform init install provider plugins?

    1. In the .terraform directory of the working directory
    2. In the state file
    3. In /usr/local/bin next to terraform
    4. In the backend's storage bucket
    Show answer

    Answer: A. In the .terraform directory of the working directory

    Providers go under .terraform/providers. A shared plugin cache can be set with TF_PLUGIN_CACHE_DIR.

  9. Question 9. How does Terraform core work with providers?

    1. Providers are compiled into the Terraform binary
    2. Providers are separate plugin binaries that Terraform calls over RPC
    3. Providers run as services in each cloud account
    4. Providers are HCL files read at plan time
    Show answer

    Answer: B. Providers are separate plugin binaries that Terraform calls over RPC

    Each provider runs as its own process, so providers are released and versioned independently of Terraform.

  10. Question 10. What does a Terraform provider do?

    1. Stores and locks state for a team of users
    2. Formats and validates configuration files
    3. Translates resources into API calls for a platform
    4. Schedules and queues runs in HCP Terraform
    Show answer

    Answer: C. Translates resources into API calls for a platform

    A provider defines resource and data source types and handles the create, read, update, and delete calls for them.

  11. Question 11. How do you configure the AWS provider for two regions in one configuration?

    1. Set region to a list of two values
    2. Use two separate state files
    3. Run terraform init twice with different flags
    4. Add a second provider "aws" block with an alias
    Show answer

    Answer: D. Add a second provider "aws" block with an alias

    The block without an alias is the default. The aliased one, for example alias = "west", is used only where a resource selects it.

  12. Question 12. Which resource argument makes a resource use the aliased provider configuration aws.west?

    1. provider = aws.west
    2. region = aws.west
    3. alias = "west"
    4. depends_on = [aws.west]
    Show answer

    Answer: A. provider = aws.west

    The provider meta-argument selects a non-default configuration. Without it, the resource uses the default aws provider.

  13. Question 13. How do you pass the aliased provider aws.west to a child module as its default aws provider?

    1. Set alias = "west" inside the child module
    2. Add providers = { aws = aws.west } to the module block
    3. Use depends_on = [aws.west] in the module block
    4. Child modules can't use aliased providers
    Show answer

    Answer: B. Add providers = { aws = aws.west } to the module block

    The providers map in the module block decides which provider configurations the child sees.

  14. Question 14. Which command lists the providers required by the configuration and the state?

    1. terraform version -providers
    2. terraform plugins
    3. terraform providers
    4. terraform list providers
    Show answer

    Answer: C. terraform providers

    terraform providers shows a tree of provider requirements, including those from modules.

  15. Question 15. Your team uses Linux in CI and Apple silicon laptops. Which command adds checksums for both platforms to the lock file?

    1. terraform providers lock -platform=linux_amd64 -platform=darwin_arm64
    2. terraform init -upgrade -platform=linux_amd64,darwin_arm64
    3. terraform get -platforms=linux_amd64 -platforms=darwin_arm64
    4. terraform lock add -os linux_amd64 -os darwin_arm64
    Show answer

    Answer: A. terraform providers lock -platform=linux_amd64 -platform=darwin_arm64

    By default init records hashes only for the current platform. providers lock adds the others so init succeeds everywhere.

  16. Question 16. Which setting constrains the Terraform CLI version that can run a configuration?

    1. version in the backend block
    2. terraform_version in a provider block
    3. cli = in the required_providers block
    4. required_version in the terraform block
    Show answer

    Answer: D. required_version in the terraform block

    For example required_version = ">= 1.12, < 2.0". Terraform refuses to run if its version doesn't match.

  17. Question 17. Where should a provider's cloud credentials usually come from?

    1. Hard-coded as arguments in the provider block
    2. Environment variables or the platform's credential chain
    3. A comment at the top of main.tf for reference
    4. A terraform.tfvars file committed to the repository
    Show answer

    Answer: B. Environment variables or the platform's credential chain

    Keeping credentials out of configuration avoids leaking them in version control. Providers read standard environment variables, profiles, or workload identity.

  18. Question 18. A configuration uses random_id resources but has no provider "random" block. What happens?

    1. Terraform fails to plan
    2. Terraform asks for the provider settings interactively
    3. Terraform uses the provider with its default, empty configuration
    4. The resources are skipped
    Show answer

    Answer: C. Terraform uses the provider with its default, empty configuration

    A provider block is only needed for settings. Declaring the source in required_providers is still good practice.

  19. Question 19. What is Terraform state?

    1. A record mapping configuration to real resources and their attributes
    2. A list of every command run in the directory
    3. The provider binaries for a project
    4. The variables file for each environment
    Show answer

    Answer: A. A record mapping configuration to real resources and their attributes

    State tells Terraform which real object (such as an instance ID) each resource address refers to.

  20. Question 20. With no backend configured, where does Terraform store state?

    1. In the .terraform directory only
    2. In a hidden HCP Terraform workspace
    3. In the provider's cloud account
    4. In terraform.tfstate in the working directory
    Show answer

    Answer: D. In terraform.tfstate in the working directory

    This is the local backend. It's fine for learning, but teams need a shared remote backend.

  21. Question 21. Why does Terraform keep state instead of looking up every resource on each run?

    1. Cloud APIs don't allow existing resources to be listed
    2. It maps resources to real IDs, tracks metadata and dependencies, and speeds up runs
    3. State is needed only when HCP Terraform runs the plans
    4. It stores the provider source code that the plan needs to run
    Show answer

    Answer: B. It maps resources to real IDs, tracks metadata and dependencies, and speeds up runs

    Many objects can't be matched to configuration by name alone, and state also remembers dependencies for correct destroy order.

  22. Question 22. Can Terraform state contain sensitive data?

    1. No, sensitive values are never written
    2. Only when the local backend is used
    3. Yes, it can hold secrets in plain text, so protect it
    4. Only if TF_LOG is set
    Show answer

    Answer: C. Yes, it can hold secrets in plain text, so protect it

    Passwords and keys often end up in state. Use a backend with encryption and access control, and never commit state to version control.

  23. Question 23. What is the recommended way to change resource entries in a state file?

    1. Edit terraform.tfstate in a text editor
    2. Use terraform state subcommands or config blocks such as moved
    3. Delete the file and run apply again
    4. Rename the resource in the cloud console
    Show answer

    Answer: B. Use terraform state subcommands or config blocks such as moved

    Hand edits can corrupt state. The state commands and moved, import, and removed blocks keep it consistent.

  24. Question 24. On the public Terraform Registry, what marks an official provider?

    1. It is owned and maintained by HashiCorp
    2. It has more than a million downloads
    3. It was published by any verified company
    4. It's built into the Terraform binary
    Show answer

    Answer: A. It is owned and maintained by HashiCorp

    Official providers are owned and maintained by HashiCorp. Partner providers are maintained by technology partners, and community providers by individuals or groups.

  25. Question 25. Which setting lets several working directories share downloaded provider plugins instead of downloading them each time?

    1. TF_DATA_DIR
    2. TF_PLUGIN_CACHE_DIR
    3. TF_INPUT
    4. TF_WORKSPACE
    Show answer

    Answer: B. TF_PLUGIN_CACHE_DIR

    With a plugin cache, init links or copies providers from the cache, saving bandwidth and time.

HashiCorp, Terraform, and HCP Terraform are trademarks of HashiCorp, Inc. These questions are original study material, not questions from the real exam.