Terraform Associate · Domain 1 of 8 · 8% of the exam

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

  1. Question 1. What is infrastructure as code (IaC)?

    1. Drawing infrastructure diagrams by hand
    2. Configuring servers through a web console
    3. Managing infrastructure through machine-readable definition files
    4. Running scripts only on physical hardware
    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.

  2. Question 2. Which is a main benefit of managing infrastructure as code?

    1. Changes are versioned, reviewed, and repeatable
    2. Infrastructure no longer needs any testing
    3. Cloud bills are always lower
    4. Servers never need patching again
    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.

  3. Question 3. Terraform's configuration language is declarative. What does that mean?

    1. You list each API call in the order to run it
    2. You describe the end state, and Terraform works out the steps
    3. You write a shell script for every resource
    4. Terraform can only read existing infrastructure
    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.

  4. Question 4. How does Terraform work with so many clouds and services?

    1. By converting configs into CloudFormation
    2. By running an agent on every server
    3. Through provider plugins for each platform's API
    4. By supporting only the three largest clouds
    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.

  5. Question 5. What does it mean that Terraform supports multi-cloud workflows?

    1. One resource type that deploys unchanged to any cloud provider
    2. Automatic failover of resources from one cloud to another
    3. Copying the same state file between cloud accounts on apply
    4. One language and workflow across providers, with provider-specific resources
    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.

  6. Question 6. Running terraform apply again with an unchanged configuration and no drift makes no changes. Which property is this?

    1. Idempotence
    2. Immutability
    3. Elasticity
    4. Portability
    Show answer

    Answer: A. Idempotence

    Because Terraform converges on the declared state, a repeated apply with nothing to change does nothing.

  7. Question 7. How does Terraform's main role differ from configuration management tools such as Ansible?

    1. Terraform provisions infrastructure; config tools mainly set up software on servers
    2. Terraform only installs and updates software packages on hosts
    3. Configuration tools can't run against servers in a public cloud
    4. Terraform must run as an agent on every server it manages
    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.

  8. Question 8. Why keep Terraform configuration in version control?

    1. Terraform refuses to run outside a repository
    2. It encrypts the state automatically
    3. To track and review changes, and roll back by commit
    4. So providers download faster
    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.

  9. Question 9. What does an immutable infrastructure approach mean?

    1. Resources are locked so nobody can ever delete them
    2. Replacing resources with new ones instead of changing them in place
    3. Changing running servers by hand whenever they need updates
    4. Running all of the infrastructure on a single large machine
    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.

  10. Question 10. Which can Terraform manage through providers, besides cloud virtual machines?

    1. Only physical servers in a data center
    2. Only resources from a single cloud vendor
    3. Only container images on a laptop
    4. DNS records, SaaS settings, and monitoring alerts
    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.

  11. Question 11. Teams change production by hand in a console, and environments slowly diverge. Which problem is this?

    1. Provider lock-in
    2. Configuration drift
    3. State locking
    4. Dependency inversion
    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.

  12. Question 12. Which language is Terraform configuration usually written in?

    1. YAML only
    2. Python with a Terraform SDK
    3. HashiCorp Configuration Language (HCL)
    4. XML with schema files
    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.

  13. Question 13. How does Terraform support hybrid cloud?

    1. It converts on-premises servers into cloud VMs
    2. It only supports public clouds
    3. It requires a separate tool for each site
    4. One workflow with providers for on-premises platforms and public clouds
    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.

  14. Question 14. What is a benefit of reusing shared IaC modules across teams?

    1. Consistent, tested patterns instead of copied code
    2. Each team must write its own providers
    3. State no longer needs to be stored
    4. Plans no longer need review
    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.

  15. Question 15. Terraform builds a dependency graph of resources. What does this let it do?

    1. Skip the plan step whenever a change is small enough
    2. Create independent resources in parallel and dependent ones in order
    3. Store state safely without configuring any backend
    4. Run plans and applies without any providers installed
    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.