Interview Insights · Cloud Tools
The Cloud Tools Question That Ninety Percent of Candidates Fumble
Quick summary — Terraform drift
The drift question is fumbled because candidates answer only the tool part and forget the people part. Technically, the next plan will show the difference and an apply will put the resource back to match the code. That is the part most candidates know. What they miss is that the manual change might have been an emergency fix that keeps production alive. Overwriting it blindly can cause an outage. A strong answer detects the drift, asks why it happened, decides which side is right, reconciles them and then reduces the chance of it happening again.
In this guide you will learn:
- Exactly what Terraform does when real infrastructure differs from code
- Why the obvious answer can cause an outage
- Refresh-only plans, import blocks and ignore_changes and when each fits
- How teams prevent drift with permissions and detection
- A model answer you can adapt in under two minutes
SECTION 01What Terraform actually does when reality changes
Terraform keeps a state file that records what it believes exists. When you run terraform plan, it first refreshes that state by reading the real resources from the cloud API. Then it compares three things: your code, the refreshed state and what it would need to change to make reality match the code. If someone added a rule by hand, the plan will propose removing it, because the code does not include it.
That is the mechanical part of the answer, and it is worth saying precisely. Many candidates say 'Terraform will give an error' or 'Terraform will not notice', and both are wrong for normal managed attributes.
| Manual change in console | What the next plan shows | Effect of a blind apply | Hidden risk |
|---|---|---|---|
| Extra inbound rule added to a security group | ~ update removing the rule | The rule is deleted | If it was an emergency fix, access breaks |
| Instance type changed to a larger size | ~ update back to the smaller type | Instance resized down, may restart | Performance problem returns |
| Resource deleted by hand | + create a new one | A fresh, empty resource appears | Data from the old one is gone |
| New resource created by hand | Nothing; Terraform does not know about it | Stays unmanaged | Forgotten cost and security gaps |
$ terraform plan
aws_security_group.app: Refreshing state... [id=sg-0abc123]
Terraform will perform the following actions:
# aws_security_group.app will be updated in-place
~ resource "aws_security_group" "app" {
id = "sg-0abc123"
~ ingress = [
- {
- cidr_blocks = ["203.0.113.10/32"]
- from_port = 22
- to_port = 22
- protocol = "tcp"
# (other attributes hidden)
},
# (1 unchanged element hidden)
]
}
Plan: 0 to add, 1 to change, 0 to destroy."On the next plan, Terraform refreshes the security group
from AWS, sees an ingress rule that is not in the code,
and proposes an in-place update that removes it.
If someone runs apply without reading, the rule is gone.
So before anything, I want to know who added that rule
and why. It could be a mistake, or it could be someone
debugging an incident at night."
Notice the last sentence of the spoken answer. That is where most candidates stop being average. They connect the tool's behaviour to a real situation on a team.
SECTION 02Reconciling: choose which side is the truth
Once you know why the change happened, you choose. If the manual change was a mistake, you let Terraform revert it with a normal plan and apply. If the manual change was correct, you update the code to include it, so the next plan shows no changes. And if a resource was created entirely by hand and should now be managed, you bring it under Terraform with an import.
There is also a case where drift is expected: some attributes are changed by other systems on purpose, such as an Auto Scaling group's desired capacity. For those, ignore_changes tells Terraform not to fight the other system.
| Situation | Right action | Tool or command | What to watch |
|---|---|---|---|
| Manual change was a mistake | Revert to match code | terraform plan, then apply | Confirm nobody depends on the change |
| Manual change was a valid fix | Update code to match reality | Edit .tf, plan shows no changes | Review and merge through the normal process |
| Resource created by hand, should be managed | Import into state | import block or terraform import | Write matching code before applying |
| Attribute changed by automation on purpose | Stop Terraform fighting it | lifecycle ignore_changes | Only ignore what truly belongs to the other system |
# Terraform 1.5 and later: declarative import
import {
to = aws_s3_bucket.reports
id = "myproj-reports-ap-south-1"
}
resource "aws_s3_bucket" "reports" {
bucket = "myproj-reports-ap-south-1"
}
# Run:
# terraform plan
# The plan shows the bucket will be imported.
# Adjust the resource block until the plan shows
# no other changes, then apply.
# Older CLI style, same effect:
# terraform import aws_s3_bucket.reports myproj-reports-ap-south-1resource "aws_autoscaling_group" "app" {
name = "app-asg"
min_size = 2
max_size = 6
desired_capacity = 2
vpc_zone_identifier = var.private_subnet_ids
launch_template {
id = aws_launch_template.app.id
version = "$Latest"
}
lifecycle {
# Scaling policies change this at runtime.
# Without this, every apply would reset capacity to 2.
ignore_changes = [desired_capacity]
}
}
A refresh-only plan is also worth mentioning. terraform plan -refresh-only shows how state differs from reality without proposing changes to resources, and terraform apply -refresh-only updates the state to accept what is there. It is useful when you want Terraform to record reality first and then decide what the code should say.
Be careful with ignore_changes. If you ignore too much, Terraform stops protecting you, and real drift goes unnoticed. Ignore only attributes that another system is meant to own.
SECTION 03Preventing drift and the model answer
The final part of a strong answer is prevention. Teams reduce drift by limiting who can change production in the console, routing changes through pull requests and running scheduled plans to detect drift early. Some also use services such as AWS Config to flag changes to sensitive resources like security groups.
Put together, a complete answer has four steps: detect, ask, reconcile and prevent. It takes about two minutes to say. The table shows the prevention options and the tab gives a model answer you can adapt.
| Prevention method | How it works | Strength | Limitation |
|---|---|---|---|
| Read-only console for most people | IAM grants write access only to the pipeline role | Removes most casual changes | Needs a break-glass process for emergencies |
| Scheduled drift check | A CI job runs terraform plan daily and alerts on changes | Catches drift quickly | Only covers resources Terraform manages |
| AWS Config rules | Records configuration changes and evaluates rules | Sees changes to any supported resource | Extra setup and cost |
| Break-glass with follow-up | Emergency access is logged and must be codified after | Allows urgent fixes safely | Relies on people following the process |
"On the next plan, Terraform refreshes the security group
and proposes removing the rule, since it is not in code.
A blind apply would delete it.
So first I would find out why it was added, from the
team or CloudTrail. If it was a mistake, I let Terraform
revert it. If it was a needed fix, I add the rule to the
code through a pull request, so the plan becomes clean.
To prevent repeats, I would keep console write access
limited, run a scheduled plan that alerts on drift, and
have a break-glass process where emergency changes are
codified the next working day."name: drift-check
on:
schedule:
- cron: '30 3 * * *'
workflow_dispatch:
permissions:
id-token: write
contents: read
jobs:
plan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: hashicorp/setup-terraform@v3
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.TF_READONLY_ROLE }}
aws-region: ap-south-1
- run: terraform init -input=false
# -detailed-exitcode: 0 = no changes, 2 = changes, 1 = error
- run: terraform plan -input=false -detailed-exitcode
The -detailed-exitcode flag is the small detail that makes the scheduled check work: exit code 2 means changes were found, so the job fails and someone gets notified. Mentioning it shows you have thought about how detection is actually wired up.
SECTION 04Drift practice lab and answer card
You can practise this whole question in a practice account in under an hour. These tabs give you the lab steps, an answer card to memorise the structure and a self-check.
DRIFT LAB
1. Create a security group with one rule in Terraform.
2. In the console, add a second inbound rule (your IP).
3. Run terraform plan. Read what it proposes.
4. Run terraform plan -refresh-only. Compare.
5. Option A: apply normally and watch the rule vanish.
6. Option B: add the rule to code; plan should be clean.
7. Create a bucket by hand; bring it in with an import block.
8. terraform destroy at the end.DRIFT ANSWER CARD
DETECT Next plan shows the difference.
Blind apply would revert it.
ASK Who changed it and why?
Check with team, CloudTrail.
RECONCILE Mistake -> let Terraform revert.
Valid -> update code via PR.
Unmanaged-> import.
Owned by automation -> ignore_changes.
PREVENT Limit console writes, scheduled plan,
break-glass process.CAN I EXPLAIN THESE IN ONE SENTENCE EACH?
[ ] What terraform plan does before comparing
[ ] What -refresh-only changes and what it does not
[ ] When to use an import block
[ ] When ignore_changes is right, and when it is risky
[ ] What -detailed-exitcode returns
[ ] How CloudTrail helps find the person and time
[ ] What a break-glass process is
SECTION 05Tips for answering drift and state questions
These tips apply to the drift question and to its many variations, such as 'someone deleted a resource' or 'state is out of date'.
- State the mechanics precisely — Say that plan refreshes from the real API and then compares with code; it shows you know how the tool works.
- Pause before the apply — Always say you would read the plan and ask why before applying anything that reverts a manual change.
- Name both directions — Explain that sometimes the code is wrong and should be updated, not only that reality should be reverted.
- Know your import options — Mention both the import block and the older terraform import command, and that code must match before you apply.
- End with prevention — A short line about access control and scheduled drift checks shows you think about the system, not just the incident.
SECTION 06Interview Q&A — Terraform drift
Q1What happens on terraform plan if a resource was changed manually?
Terraform refreshes the resource's real attributes from the provider API, compares them to the configuration and proposes changes to bring reality back in line with the code. For a manually added rule, the plan will show an in-place update that removes it.
Q2What does terraform plan -refresh-only do?
It shows how the state file differs from the real infrastructure without proposing changes to the resources themselves. Running apply -refresh-only then updates the state to match reality. It is useful to record what is actually there before deciding how the code should change.
Q3How do you bring a manually created resource under Terraform?
Write a resource block for it and import it, either with an import block in configuration, available from Terraform 1.5, or the terraform import command. Then adjust the resource block until the plan shows no unexpected changes, and apply.
Q4When would you use ignore_changes?
When another system legitimately manages an attribute, such as Auto Scaling changing desired_capacity, or tags added automatically by a separate tool. Without it, every apply would undo those changes. I would ignore only those specific attributes, not whole resources.
Q5How would you find out who changed a resource in AWS?
Search CloudTrail event history for API calls on that resource, such as AuthorizeSecurityGroupIngress for a security group rule. The event shows the identity, time, source IP and request details. AWS Config can also show the configuration timeline for supported resources.
SECTION 07Test yourself — Terraform drift quiz
Five questions. No sign-up.
0 / 5Pick an answer to see why it is right or wrong.
SECTION 08Frequently asked questions
What is drift in Terraform?
Drift is a difference between what your Terraform code and state describe and what actually exists in the cloud, usually caused by manual changes or other tools modifying resources. Terraform shows it on the next plan.
How do you detect configuration drift in AWS?
Run terraform plan regularly, for example in a scheduled CI job with -detailed-exitcode. AWS Config can also record configuration changes and evaluate rules, and CloudTrail records the API calls that made the changes.
What is the difference between terraform refresh and plan -refresh-only?
The older terraform refresh command updated state directly without showing you what changed. plan -refresh-only shows the differences first, and apply -refresh-only updates state after you review them, which is the safer recommended approach.
How do I import existing AWS resources into Terraform?
Write a resource block, then use an import block with the target address and the resource ID, or run terraform import. Run plan, adjust the code until no unexpected changes appear and then apply to record it in state.
Should I make changes in the AWS console if I use Terraform?
Ideally not for resources Terraform manages, because it causes drift. Use the console to explore and to handle real emergencies, then put any lasting change into code through the normal review process.
Does Uncodemy help with Cloud Tools interview questions?
Yes. Uncodemy's Cloud Computing Training Course in Noida (classroom and online) includes live projects, one-to-one mock interviews and resume reviews, so you practise Cloud Tools interview questions with trainer feedback before the real interview. You can book a free demo class from this page to see how the sessions work.
SECTION 09Related reads
Classroom & online · Noida
Answer the drift question with confidence
Our Cloud Computing Training Course includes Terraform labs on state, drift, imports and CI checks, so you can handle the tools questions most candidates fumble.
Talk to a counsellor for current fees- Terraform state and drift labs
- CI/CD with plan checks
- Mock cloud tools rounds
- Weekday & weekend batches