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 variablessensitive. - Cost: labels on everything,
infracostestimates 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 →
- Question 1easy
What is drift?
- 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?
- Question 3medium
What does
terraform apply -refresh-onlydo? - Question 4medium
A bucket made by hand two years ago should now be managed by Terraform. What's the modern approach?
- Question 5hard
Your import plan shows "1 to import, 1 to change". What does that tell you?
Drift, imports, secrets and cost
Drift, imports, secrets and cost
Drift, imports, secrets and cost
Drift, imports, secrets and cost
Drift, imports, secrets and cost
9 more questions on this topic, with hints, and tests
Sign up free for 21 days of every question and test.