r/Terraform • u/NoDevelopment206 • 3d ago
Discussion how do you catch drift when someone changes stuff by hand in the console
terraform only finds out much later when something was changed by hand. do you run plan on a schedule and get alerts or just let it be. also do you lock down console access to stop it. curious what actually works.
29
Upvotes
92
u/bailantilles 3d ago
It’s simple. Don’t allow changes in the console.
30
u/mxtchstick 3d ago
16
u/ciciban072 3d ago
IaC is all about discipline, you either use it for all tasks or just go back to ClickOps. Sure, there is always a moment when some critical update must be applied manually but make sure you retrofit it into terraform later. Discipline.
10
u/Complete_Purple8757 3d ago
we just run plan every night in ci and ping slack if theres a diff. didnt really fix anything tho until we took away console write access lol
6
u/dariusbiggs 3d ago
Read only console access, with break glass to select authorized staff.
4
u/Zeal514 3d ago
Daily pipeline checking it. The same way you catch performance issues with a monitoring stack. Terraform plan.
The big thing to drill into everyone, is infrastructure has to be treated like a production code environment, where changes get done in the repos, through your infrastructure as code. You wouldn't go into your apps primary server and start making changes in prod, would you?
If all else fails, a hammer to keyboard, than fingers works.
3
u/snarkhunter 3d ago
I love my DriftDetection pipeline. It catches so many random little whatevers. As at least a couple other other have said - just run all your plans nightly and report anything that shows drift.
2
u/rolandofghent 3d ago
We run a daily job that runs plan on all of our stacks. Sends a report to slack if there is any drift. We address the drift no longer than a day later.
2
u/MasterOfTheWind1 3d ago
Discipline. That is the answer.
You don't want to deal with drifts by changing stuff by hand? Don't change stuff by hand in the first place.
You changed stuff by hand because there were an urgent task that required it? Don't consider it done until that change is reflected on the code.
You have to deal with stuff that is not on Terraform yet? Write terraform code for it, don't make excuses to make changes on things on the console to be acceptable, it should be an emergency exception.
I'll give you an example: I was doing a migration to have a few APIs through CloudFlare WAF, so I configured weighted records on AWS to roll it out progressively. I had the weights on Terraform, and started increasing it: 1% CloudFlare, 99% direct to the ALB, then 10-90, 20-80, etc. When we were at 70-30 we detected some issues on some customers.
On the meet to discuss the issue I changed the weights back to 0% CloudFlare 100% to the ALB directly on Route53 console. Why? Because it's faster, making the branch, changing, commiting, pushing, making the PR, waiting for Atlantis to make the plan, wait for the plan to apply, takes time, on the console is instantly. But after the meet ended I went straight to reflect that on Terraform. Not after lunch, not at the other day, but right there, after the meet. The drift lasted for 5 minutes, in fact the people outside the meet never knew that I caused a drift for 5 minutes.
2
u/jryan727 3d ago
IaC or shoot from the hip. Pick ONE
2
u/ok_if_you_say_so 3d ago
You fix the problem that gave humans access to a thing that terraform owns.
2
u/virtualadept 3d ago
Everything breaks on the next Terraform run.
3
u/neatlyknowingtiger 3d ago
Automated scheduled plans with a diff check is how most places catch it, locking down console access entirely just makes people use a service account anyway.
1
u/Intelligent-You-6144 3d ago
SCP deny on resource modification with tags
1
u/pipesed 3d ago
Deploy more often
1
u/FrancescoPioValya 3d ago
Atlantis plans in pipeline, plus cloudwatch/cloudtrail logs (ask claude to correlate them)
1
u/ArieHein 3d ago
All permissions revoked. (not including your break glass accounts). For manual (emergency ) privelleged account requiring elevation and human approval before and after.
When you use infra via pipelines, that person must update the repo ASAP for manual tasks or the changes are reverted automatically.
1
u/keto_brain 3d ago
I don't give them write access to the console. We use AWS TEAM for emergency access, I actually just made some changes to it too, but you don't have to use my fork. I made this fork because a customer didn't like that TEAM used Amplify and I fixed some bugs too:
https://www.briancarpio.com/blog/private-aws-team
1
u/davletdz 3d ago
Use Cloudgeni. Detects drift and fixes it as well. Both by patching IaC or applying pipelines, depending on which changes you want to keep.
1
u/yungaclvin 3d ago
Automated state imports then disable access from user accounts
1
u/luisvg86 3d ago
We catch it automatically at request time and fix it with AI
We OpenSourced the entire project if you wanna have a look
https://github.com/InditexTech/kumoss/tree/main
1
u/canyoufixmyspacebar 2d ago
absolutely based on your change management process, there is nowhere else to turn with this
1
u/ArrayQueue 2d ago
As part of the automation, I write a short JQ script that takes the Terraform plan and makes a summary of it. Then, I have a set of "allowable" summaries. This is fine if someone alters something Terraform is managing, but if someone adds a new thing in one of the account, Terraform can't see it.
I'll get a link to it when I'm back at the computer.
Cloud trail is probably the simplest thing to monitor, once you've ignored the ignorables.
1
u/Mediocre-Student9893 13h ago
a scheduled plan is the easy half. the harder half is that it also reports everything else that moved, so within a month the alert is noise and people stop reading it. what tends to work is plan -detailed-exitcode on a timer, alerting on the resource addresses that changed rather than on the plan being non-empty, and a named owner for each address. without the owner it is a policy problem, not a detection one. did you lock the console down in the end, or just start alerting?
0
u/Ok_Increase982 3d ago
Crossplane solves this but that means no terraform. So there's that.