Terraform Associate Domain 1: Infrastructure as Code (IaC) with Terraform
15 free practice questions for Infrastructure as Code (IaC) with Terraform in the HashiCorp Certified: Terraform Associate (004) exam. Try each question first, then open "Show answer" for the correct option and explanation.
Infrastructure as Code (IaC) with Terraform practice questions
-
Question 1. What is infrastructure as code (IaC)?
Show answer
Answer: C. Managing infrastructure through machine-readable definition files
IaC describes infrastructure in files that can be versioned, reviewed, tested, and applied repeatedly by tools such as Terraform.
-
Question 2. Which is a main benefit of managing infrastructure as code?
Show answer
Answer: A. Changes are versioned, reviewed, and repeatable
Code can go through pull requests, be reused across environments, and recreate the same setup reliably.
-
Question 3. Terraform's configuration language is declarative. What does that mean?
Show answer
Answer: B. You describe the end state, and Terraform works out the steps
You declare what should exist. Terraform compares that with state and reality and plans the creates, updates, and deletes needed.
-
Question 4. How does Terraform work with so many clouds and services?
Show answer
Answer: C. Through provider plugins for each platform's API
Providers implement resource types for an API. Thousands exist, for clouds, SaaS products, networking gear, and more.
-
Question 5. What does it mean that Terraform supports multi-cloud workflows?
Show answer
Answer: D. One language and workflow across providers, with provider-specific resources
The workflow (write, plan, apply) and HCL are the same everywhere, but an aws_instance and a google_compute_instance are still different resources.
-
Question 6. Running terraform apply again with an unchanged configuration and no drift makes no changes. Which property is this?
Show answer
Answer: A. Idempotence
Because Terraform converges on the declared state, a repeated apply with nothing to change does nothing.
-
Question 7. How does Terraform's main role differ from configuration management tools such as Ansible?
Show answer
Answer: A. Terraform provisions infrastructure; config tools mainly set up software on servers
Terraform creates and changes infrastructure resources through APIs. Config management tools focus on what runs inside machines, though the two overlap and are often combined.
-
Question 8. Why keep Terraform configuration in version control?
Show answer
Answer: C. To track and review changes, and roll back by commit
Version control gives history, code review, and a link between infrastructure changes and who made them. State itself should go in a backend, not the repository.
-
Question 9. What does an immutable infrastructure approach mean?
Show answer
Answer: B. Replacing resources with new ones instead of changing them in place
Instead of patching a server, you build a new one from updated code and remove the old one, which avoids configuration drift.
-
Question 10. Which can Terraform manage through providers, besides cloud virtual machines?
Show answer
Answer: D. DNS records, SaaS settings, and monitoring alerts
Anything with an API can have a provider: DNS, identity platforms, monitoring, version control settings, databases, and more.
-
Question 11. Teams change production by hand in a console, and environments slowly diverge. Which problem is this?
Show answer
Answer: B. Configuration drift
Manual changes aren't recorded or repeated, so environments drift apart. Applying the same code everywhere keeps them consistent.
-
Question 12. Which language is Terraform configuration usually written in?
Show answer
Answer: C. HashiCorp Configuration Language (HCL)
Configuration lives in .tf files written in HCL. Terraform also accepts a JSON form in .tf.json files, which is handy for generated code.
-
Question 13. How does Terraform support hybrid cloud?
Show answer
Answer: D. One workflow with providers for on-premises platforms and public clouds
Providers exist for platforms such as vSphere and Kubernetes as well as public clouds, so one configuration can span both.
-
Question 14. What is a benefit of reusing shared IaC modules across teams?
Show answer
Answer: A. Consistent, tested patterns instead of copied code
Modules package good practices once, so teams don't copy and diverge, and fixes reach everyone through new module versions.
-
Question 15. Terraform builds a dependency graph of resources. What does this let it do?
Show answer
Answer: B. Create independent resources in parallel and dependent ones in order
The graph tells Terraform which resources depend on which, so it can parallelize safely and destroy in reverse order.
HashiCorp, Terraform, and HCP Terraform are trademarks of HashiCorp, Inc. These questions are original study material, not questions from the real exam.