Cisco CCNA (200-301)Automation and ProgrammabilityHard

A team uses Terraform to manage cloud-hosted virtual routers. After running 'terraform apply' successfully, a teammate manually deletes one of the routers directly from the cloud provider's console. The next time the team runs 'terraform plan', Terraform reports that it needs to recreate the deleted router. How does Terraform detect that the router is missing?

  1. AIt queries DNS records to verify router reachability
  2. BIt re-reads the original HCL configuration file for change history
  3. CIt compares the actual infrastructure against its stored state file
  4. DIt relies on SNMP traps sent from the cloud provider
Show answer & explanation

Correct answer: C. It compares the actual infrastructure against its stored state file

Terraform maintains a state file that records the last known configuration of managed infrastructure. During 'terraform plan', it refreshes this state by querying the actual provider APIs and compares real-world resources against the state file; a discrepancy (like a manually deleted router) is flagged so Terraform can propose corrective action.

Why the other options are wrong

  • A. DNS is unrelated to Terraform's resource tracking mechanism.
  • B. HCL files define desired configuration, not historical change tracking.
  • D. Terraform does not rely on SNMP traps for state comparison.

Terraform State File

A file (terraform.tfstate) that tracks the current known state of managed infrastructure, used by Terraform to detect drift and determine what changes are needed to reach the desired configuration.

  • Stored typically as JSON
  • Refreshed during plan/apply to detect drift
  • Critical for accurate diffing between desired and actual state

Memory trick: The state file is Terraform's memory of what it built.

More Automation and Programmability questions