Skip to content

004 · Domain 1: Infrastructure as Code (IaC) with Terraform · 12% of the exam

Task 1.1: Explain what IaC is

Infrastructure described in files instead of built by hand: the declarative model where you state the end result and Terraform works out the steps, configuration kept in version control, and the same files producing the same infrastructure every time.

Study it

Sample questions

Try each one before opening the answer. Every option is explained, with the HashiCorp documentation page that proves it.

Question 1 · choose 1

An operations team builds every new environment by following a wiki page of console steps. A new lead wants the team to adopt infrastructure as code. Which change actually meets that goal?

  1. ADescribe the infrastructure in configuration files that a tool applies through APIs
  2. BRecord a screen video of each console session so the steps can be repeated exactly
  3. CTake a snapshot image of each finished server and restore that image in every new environment
  4. DMove the wiki page into version control so that every edit to the console steps gets a review
Show the answer and why
  • ADescribe the infrastructure in configuration files that a tool applies through APIs

    Correct

    IaC means managing infrastructure with configuration files rather than through a graphical console, so the files, not people, drive the changes.

  • BRecord a screen video of each console session so the steps can be repeated exactly

    Incorrect

    A recording still documents a manual process; a person has to repeat every click, which is what IaC replaces.

  • CTake a snapshot image of each finished server and restore that image in every new environment

    Incorrect

    Images capture one machine's disk. They do not describe or manage the networks, DNS and other infrastructure around it.

  • DMove the wiki page into version control so that every edit to the console steps gets a review

    Incorrect

    Versioning a manual procedure helps review, but the infrastructure is still built by hand. IaC versions files that a tool executes.

Infrastructure as code replaces manual, console-driven provisioning with configuration files that a tool such as Terraform applies through each platform's API, safely and repeatably.

Question 2 · choose 1

A developer used to writing shell scripts asks how a Terraform configuration differs from a script that calls a cloud CLI to create the same three servers. Which statement describes the difference?

  1. AThe configuration lists each API call in sequence, and Terraform runs them from top to bottom
  2. BThe configuration is compiled into a shell script that the cloud provider runs on its side
  3. CThe configuration describes only what to change since the last run, like a migration file
  4. DThe configuration states the end result; Terraform works out the API calls and their order
Show the answer and why
  • AThe configuration lists each API call in sequence, and Terraform runs them from top to bottom

    Incorrect

    That is the procedural model of a script. Terraform does not run blocks as a sequence of commands.

  • BThe configuration is compiled into a shell script that the cloud provider runs on its side

    Incorrect

    Terraform does not produce scripts for the provider. Its providers call the platform APIs directly.

  • CThe configuration describes only what to change since the last run, like a migration file

    Incorrect

    A Terraform configuration describes the whole desired infrastructure, not a delta; Terraform calculates the changes itself.

  • DThe configuration states the end result; Terraform works out the API calls and their order

    Correct

    Terraform's language is declarative. You describe the desired end state and Terraform handles the underlying logic instead of step-by-step instructions.

Declarative configuration describes what should exist and leaves the steps to Terraform; a script encodes the steps themselves.

Question 3 · choose 1

A configuration declares a subnet in main.tf and the VPC that the subnet references in network.tf, which sorts after main.tf alphabetically. A reviewer worries that Terraform will try to create the subnet first. What actually decides the order?

  1. ATerraform reads files in alphabetical order, so the VPC block must move into main.tf above the subnet
  2. BTerraform orders the work from the references, so the VPC is created before its subnet
  3. CTerraform creates resources in the order their blocks appear, so the reviewer must reorder the blocks
  4. DTerraform creates every resource at the same time and retries the subnet until the VPC exists
Show the answer and why
  • ATerraform reads files in alphabetical order, so the VPC block must move into main.tf above the subnet

    Incorrect

    Terraform loads all .tf files in the directory together as one configuration. File names and block order do not set the creation order.

  • BTerraform orders the work from the references, so the VPC is created before its subnet

    Correct

    Terraform builds a resource graph to determine dependencies; the subnet's reference to the VPC places it after the VPC whatever the file order.

  • CTerraform creates resources in the order their blocks appear, so the reviewer must reorder the blocks

    Incorrect

    Block order has no effect on execution in a declarative configuration; the graph does.

  • DTerraform creates every resource at the same time and retries the subnet until the VPC exists

    Incorrect

    Terraform does run independent resources in parallel, but it waits for dependencies instead of retrying blindly.

Order in files means nothing to Terraform. References between resources become edges in the dependency graph, and Terraform walks that graph, running independent nodes in parallel.

Question 4 · choose 1

A team built a database cluster with Terraform last month. Now it must double the cluster's storage. Under infrastructure as code, how should the change be made?

  1. AEdit the storage value in the configuration, review the plan and apply
  2. BWrite a second configuration that contains only the storage change for this cluster
  3. CChange the storage in the console and add a note to the repository
  4. DRun terraform init with the new storage value as an option
Show the answer and why
  • AEdit the storage value in the configuration, review the plan and apply

    Correct

    Terraform manages infrastructure throughout its lifecycle with the same workflow, so later changes go through the configuration as well.

  • BWrite a second configuration that contains only the storage change for this cluster

    Incorrect

    A second configuration for one change would split management of the same object.

  • CChange the storage in the console and add a note to the repository

    Incorrect

    A console change leaves the configuration describing the old value.

  • DRun terraform init with the new storage value as an option

    Incorrect

    init prepares the working directory; it does not take resource values.

IaC covers the whole life of the infrastructure. Every change, not only the first build, goes through the files and the plan.

Question 5 · choose 1

An internal tool generates infrastructure definitions from a service catalog and must hand them to Terraform without a person editing HCL. What does Terraform support for this?

  1. APassing YAML files to terraform apply with a -config option
  2. BWriting the definitions directly into terraform.tfstate before running apply
  3. CWriting the configuration in JSON syntax in files that end in .tf.json
  4. DSaving the definitions as a plan file and applying that plan
Show the answer and why
  • APassing YAML files to terraform apply with a -config option

    Incorrect

    Terraform has no YAML configuration format or -config option.

  • BWriting the definitions directly into terraform.tfstate before running apply

    Incorrect

    State records what Terraform manages; it is never a way to declare new infrastructure.

  • CWriting the configuration in JSON syntax in files that end in .tf.json

    Correct

    Terraform reads configuration in its native syntax (.tf) and in a JSON-based variant (.tf.json) meant for files generated by programs.

  • DSaving the definitions as a plan file and applying that plan

    Incorrect

    Plan files are produced by terraform plan, not written by other tools.

Configuration is plain text in either HCL or JSON, so both people and programs can produce it.

Question 6 · choose 1

A teammate argues that because Terraform is declarative, a configuration cannot contain any logic, so per-environment differences need a separate copy of the files for each environment. What is the better answer?

  1. ALogic is allowed only inside provisioners, which run shell commands
  2. BIt stays declarative but has variables, conditionals, for expressions and functions
  3. CTerraform has an imperative mode that is switched on with a command-line flag
  4. DSeparate copies are the only option, because variables cannot change which resources exist
Show the answer and why
  • ALogic is allowed only inside provisioners, which run shell commands

    Incorrect

    Provisioners run commands on resources; configuration logic lives in expressions.

  • BIt stays declarative but has variables, conditionals, for expressions and functions

    Correct

    Terraform expressions include conditionals, for expressions and built-in functions, which compute values while the configuration still describes an end state.

  • CTerraform has an imperative mode that is switched on with a command-line flag

    Incorrect

    There is no imperative mode; Terraform is always declarative.

  • DSeparate copies are the only option, because variables cannot change which resources exist

    Incorrect

    Input variables exist precisely to customize a configuration without copying it.

Declarative does not mean static. Expressions compute the values of the end state you describe.

Question 7 · choose 1

A team lists items it wants to manage with Terraform. Which item can Terraform NOT manage, whatever provider is used?

  1. ADNS records in a hosted DNS service
  2. BListener rules on a cloud load balancer
  3. CObject storage buckets and their access policies
  4. DPhysical patch cables between two switches
Show the answer and why
  • ADNS records in a hosted DNS service

    Incorrect

    DNS records are a documented example of a high-level component Terraform manages.

  • BListener rules on a cloud load balancer

    Incorrect

    Networking components such as load balancers are managed through the cloud provider's API.

  • CObject storage buckets and their access policies

    Incorrect

    Storage is one of the low-level components Terraform manages through a provider.

  • DPhysical patch cables between two switches

    Correct

    Terraform manages infrastructure through APIs. A physical cable has no API, so no provider can create or change it.

The limit of IaC with Terraform is the API. Something that cannot be driven through an API cannot be described in configuration and applied.

Practise domain 1 →Practise all domains →