TF-Associate-004 - Core Terraform workflow (19% of the exam) - Section 3f
Destroy Terraform-managed infrastructure.
terraform destroy removes all resources tracked in state for the configuration; a targeted destroy or -target scopes it. Candidates should understand destroy operates on managed state, and how it differs from removing a resource block and applying.
terraform destroydestroy operates on statetargeted destroyremoving a resource block versus destroy
Practice question for this objective
lock_openFree sampleCore Terraform workfloweasy
Aside from running 'terraform destroy', which action also causes Terraform to delete a managed resource on the next apply?
ACommenting out the resource's arguments while leaving the resource block header in place.
BSetting the resource's 'count' meta-argument to a value of one.
CAdding a 'depends_on' entry so the resource waits for another resource first.
DRemoving the resource block from the configuration entirely, then running apply.check_circle Correct
Understand that removing a resource block and applying destroys that resource, an alternative to terraform destroy. Apply reconciles configuration against state, so a resource still in state but absent from configuration is scheduled for destruction; deleting the block is therefore a targeted way to remove one resource.
Why A is wrong: Removing arguments changes the resource's settings and usually triggers an update or replacement, but as long as the block remains Terraform still manages the resource rather than deleting it.
Why B is wrong: A count of one keeps a single instance of the resource, so nothing is destroyed; only reducing count below the number of existing instances would remove any.
Why C is wrong: depends_on only orders operations and does not delete anything, so it changes when a resource is created but never causes its removal.
Why D is correct: Correct: with the block gone, Terraform sees a resource in state that is no longer in the configuration and plans to destroy it on apply.
Answers that look right on this material and are not. Each one is a distractor from a different question in the TF-Associate-004 bank for this domain.
terraform apply -destroy=false
errorWhy it is wrong: This looks like a plausible flag toggle, but -destroy=false is not how you request destruction; a plain apply reconciles to the desired state and would not remove the resources.
It leaves the bucket unchanged, because removing a block only stops Terraform from managing that resource
errorWhy it is wrong: This confuses deleting a block with terraform state rm; simply removing the block does not detach the resource, so apply will still act on the difference and destroy it.
It deletes the Terraform configuration files from the working directory while leaving the real infrastructure running.
errorWhy it is wrong: This is tempting because destroy sounds like a general delete, but the command removes the managed infrastructure, not the .tf source files, which stay on disk untouched.