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
-
Question 1. Which block declares the providers a configuration needs and where to get them?
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.
-
Question 2. What does the provider source address hashicorp/aws mean?
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.
-
Question 3. Which versions does the constraint version = "~> 5.4" allow?
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.
-
Question 4. Which versions does the constraint version = "~> 5.4.1" allow?
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.
-
Question 5. What does the .terraform.lock.hcl file record?
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.
-
Question 6. Should the dependency lock file .terraform.lock.hcl be committed to version control?
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.
-
Question 7. Which command upgrades providers to the newest versions their constraints allow, updating the lock file?
Show answer
Answer: D. terraform init -upgrade
Without -upgrade, init keeps the versions recorded in the lock file.
-
Question 8. By default, where does terraform init install provider plugins?
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.
-
Question 9. How does Terraform core work with providers?
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.
-
Question 10. What does a Terraform provider do?
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.
-
Question 11. How do you configure the AWS provider for two regions in one configuration?
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.
-
Question 12. Which resource argument makes a resource use the aliased provider configuration 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.
-
Question 13. How do you pass the aliased provider aws.west to a child module as its default aws provider?
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.
-
Question 14. Which command lists the providers required by the configuration and the state?
Show answer
Answer: C. terraform providers
terraform providers shows a tree of provider requirements, including those from modules.
-
Question 15. Your team uses Linux in CI and Apple silicon laptops. Which command adds checksums for both platforms to the lock file?
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.
-
Question 16. Which setting constrains the Terraform CLI version that can run a configuration?
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.
-
Question 17. Where should a provider's cloud credentials usually come from?
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.
-
Question 18. A configuration uses random_id resources but has no provider "random" block. What happens?
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.
-
Question 19. What is Terraform state?
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.
-
Question 20. With no backend configured, where does Terraform store state?
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.
-
Question 21. Why does Terraform keep state instead of looking up every resource on each 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.
-
Question 22. Can Terraform state contain sensitive data?
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.
-
Question 23. What is the recommended way to change resource entries in a state file?
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.
-
Question 24. On the public Terraform Registry, what marks an official provider?
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.
-
Question 25. Which setting lets several working directories share downloaded provider plugins instead of downloading them each time?
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.