004 · Domain 4: Terraform configuration · 13% of the exam
Task 4.6: Define resource dependencies in configuration
Implicit dependencies from references, depends_on for hidden ones, and lifecycle rules that change the order of replacement such as create_before_destroy.
Try each one before opening the answer. Every option is explained, with the HashiCorp documentation page that proves it.
Question 1 · choose 1
An application on an instance reads a bucket at startup through the instance's IAM role. The role policy that grants bucket access is a separate resource, and nothing in the instance's arguments refers to it. Sometimes the app starts before the policy exists. What fixes the order?
AMove the policy block above the instance block in the same file
BAdd lifecycle { ignore_changes = all } to the instance
CAdd depends_on = [aws_iam_role_policy.bucket_read] to the instance
DRun the apply with -parallelism=1 so resources are created one at a time
Show the answer and why
AMove the policy block above the instance block in the same file
Incorrect
Block order does not affect the dependency graph.
BAdd lifecycle { ignore_changes = all } to the instance
Incorrect
ignore_changes stops updates to attributes; it does not order creation.
CAdd depends_on = [aws_iam_role_policy.bucket_read] to the instance
Correct
depends_on handles hidden dependencies that Terraform cannot infer, when a resource relies on another's behavior without referencing its data.
DRun the apply with -parallelism=1 so resources are created one at a time
Incorrect
Lower parallelism does not guarantee the policy comes first.
References create dependencies automatically; depends_on is for the ones Terraform cannot see.
Before a refactor, an engineer wants a picture of how the resources in a configuration depend on each other, to confirm that the database waits for its subnet group. Which command produces it?
Aterraform graph, which outputs the dependency graph for visualizing
Bterraform providers, which lists every resource under the provider it depends on
Cterraform show, which draws the dependency tree of the current state
Dterraform plan -parallelism=1, which processes the resources in dependency order
Show the answer and why
Aterraform graph, which outputs the dependency graph for visualizing
Correct
By default, terraform graph prints the dependency ordering of the resources in DOT format; -type=plan adds more detail.
Bterraform providers, which lists every resource under the provider it depends on
Incorrect
providers shows the provider requirements of the configuration and its modules, not how resources depend on each other.
Cterraform show, which draws the dependency tree of the current state
Incorrect
show prints the state or a saved plan in readable form; it does not draw dependencies.
Dterraform plan -parallelism=1, which processes the resources in dependency order
Incorrect
-parallelism limits how many operations run at once; the plan output is not a map of the dependencies.
Terraform plans and applies by walking a dependency graph; terraform graph lets you look at the resource ordering instead of guessing.
A team wants Terraform to create a jump host and, weeks later, destroy it, but never to update it in place in between, whatever changes in the configuration or outside it. Which setting does this?
Alifecycle { ignore_changes = [ami, instance_type] }, listing the arguments that usually change
Blifecycle { ignore_changes = all }
Clifecycle { prevent_update = true }
DA data block for the host after its first apply, so Terraform only reads it
Show the answer and why
Alifecycle { ignore_changes = [ami, instance_type] }, listing the arguments that usually change
Incorrect
A list ignores only the attributes it names; changes to any other argument would still be planned as updates.
Blifecycle { ignore_changes = all }
Correct
With the keyword all, Terraform never updates the object but can still create or destroy it.
Clifecycle { prevent_update = true }
Incorrect
The lifecycle block has no such argument; Terraform reports it as unsupported.
DA data block for the host after its first apply, so Terraform only reads it
Incorrect
A data block stops Terraform from managing the host at all, so it could no longer destroy it either.
ignore_changes = all freezes a resource between creation and destruction. Use it sparingly: legitimate configuration changes are ignored too.
A module that configures monitoring must wait until a whole networking module has finished, but it uses none of that module's outputs. What expresses this?
Aproviders = { network = module.network }
BA moved block from the network module to the monitoring module
Cdepends_on = [module.network] in the monitoring module block
DNothing; modules always run one after another
Show the answer and why
Aproviders = { network = module.network }
Incorrect
providers passes provider configurations, not dependencies.
BA moved block from the network module to the monitoring module
Incorrect
moved blocks record address changes.
Cdepends_on = [module.network] in the monitoring module block
Correct
depends_on can be used in module blocks and can reference an entire module.
DNothing; modules always run one after another
Incorrect
Modules are part of one graph and run in parallel where possible.
Whole-module dependencies use depends_on on the module block.
An autoscaling process changes an instance group's desired_capacity all day, and every plan proposes to set it back. The team wants Terraform to set the initial value but then leave it alone. What should they add?