TECHNOLOGIESTieInn Technologies

Drift, imports, secrets and cost

Terraform · 14 questions

Short notes

Key idea

Over time, reality drifts from code: someone clicks a change in the console, or a resource was created before Terraform. Detect drift with plans, adopt existing resources with imports, keep secrets out of code and state, and watch cost.

Syntax

terraform plan -refresh-only     # show drift without changing anything
import {
  to = google_storage_bucket.legacy
  id = "old-bucket-name"
}
  • Secrets: read from Secret Manager at runtime, or pass with TF_VAR_ env vars; mark variables sensitive.
  • Cost: labels on everything, infracost estimates on pull requests, lifecycle rules.

Example

A nightly CI job runs plan -refresh-only for prod. It reports a bucket made public by hand. The team reverts it via apply, then removes console write access from that group.

Traps

  • Importing without matching code makes the next plan want to change or recreate the resource; write the block to match first.
  • Secrets passed into resources still land in state; protect the state bucket.
  • Ignoring drift lets small differences pile up until an apply surprises you.
  • lifecycle { ignore_changes } hides drift; use it only for fields another system owns.

Want the full lesson with step-by-step examples, a project and a certificate? Terraform course, ₹120 →

Questions

Open in Code Lab5 free questions
5 questions

    Drift, imports, secrets and cost

  1. Question 1easy

    What is drift?

  2. Drift, imports, secrets and cost

  3. Question 2medium

    During an incident someone turned off bucket versioning in the console. Your code says it's on. What will the next normal apply do?

  4. Drift, imports, secrets and cost

  5. Question 3medium

    What does terraform apply -refresh-only do?

  6. Drift, imports, secrets and cost

  7. Question 4medium

    A bucket made by hand two years ago should now be managed by Terraform. What's the modern approach?

  8. Drift, imports, secrets and cost

  9. Question 5hard

    Your import plan shows "1 to import, 1 to change". What does that tell you?

9 more questions on this topic, with hints, and tests

Sign up free for 21 days of every question and test.