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
What IaC is: declarative configuration that a tool converges to
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?
ADescribe the infrastructure in configuration files that a tool applies through APIs
BRecord a screen video of each console session so the steps can be repeated exactly
CTake a snapshot image of each finished server and restore that image in every new environment
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.
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?
AThe configuration lists each API call in sequence, and Terraform runs them from top to bottom
BThe configuration is compiled into a shell script that the cloud provider runs on its side
CThe configuration describes only what to change since the last run, like a migration file
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.
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?
ATerraform reads files in alphabetical order, so the VPC block must move into main.tf above the subnet
BTerraform orders the work from the references, so the VPC is created before its subnet
CTerraform creates resources in the order their blocks appear, so the reviewer must reorder the blocks
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.
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?
AEdit the storage value in the configuration, review the plan and apply
BWrite a second configuration that contains only the storage change for this cluster
CChange the storage in the console and add a note to the repository
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.
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?
APassing YAML files to terraform apply with a -config option
BWriting the definitions directly into terraform.tfstate before running apply
CWriting the configuration in JSON syntax in files that end in .tf.json
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.
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?
ALogic is allowed only inside provisioners, which run shell commands
BIt stays declarative but has variables, conditionals, for expressions and functions
CTerraform has an imperative mode that is switched on with a command-line flag
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.