Terraform Drift
Close the port in the console, and the next apply reopens it.
What Is Terraform Drift?
A security group left open to the whole internet is closed by hand in the console, and the next routine apply reopens it, because the code is the source of truth and the code still says 0.0.0.0/0. You'll watch a production database read directly from the internet, close the port in the console, see an unrelated apply revert that fix, then move the fix into code so the pipeline keeps the port closed. You'll also meet the mirror problem: a resource removed from the configuration but never destroyed.
What You'll Learn in Terraform Drift
- Terraform enforces what the code declares, so a fix made in the console is drift the next apply reverts.
- A fix has to live where the pipeline reads it, which is the code, to survive every apply.
- A connection that times out proves a network fix; an authentication error would only show the credential changed.
- Drift runs both ways: a resource removed from the configuration but never destroyed keeps running outside every audit.
Terraform Drift — Training Steps
-
A database port on the internet
Bob scans Drumhallow's addresses for database ports answering directly. One does. Drumhallow runs a business payments platform. Its production ledger database should sit behind the application, on a private network.
-
Connect to it
An open database port is an invitation. Bob connects with a credential Drumhallow reused from a staging dump, which the open port let him reach.
-
Read the ledger
The connection is live, straight from the internet, with no application in the path. Bob reads the payouts table.
-
Which control failed
-
Reachable from the internet
Drumhallow's security scan flags the ledger database as reachable from any address, and monitoring shows it was read from one it does not recognize.
-
Find the rule
The fastest way to stop the exposure is to close the rule where it is live, in the console. Alice opens the VPC security groups.
-
Open the rule
The database security group carries the open rule.
-
The whole internet, on the database port
The inbound rule allows any address to reach the database.
-
Close it by hand
Alice scopes the rule to the internal network range, so only the application subnets can reach the database. The exposure stops.
-
The apply undoes it
Overnight the pipeline runs a routine apply for an unrelated change. It detects Alice's console edit as drift and reverts the rule to what the code says: 0.0.0.0/0.
Security Framework Coverage
CWE
- CWE-668 Exposure of Resource to Wrong Sphere
CIS Controls
- CIS 4 Secure Configuration of Enterprise Assets and Software
NIST CSF
- PR.AT-02 Individuals in specialized roles are provided with awareness and training so that they possess the knowledge and skills to perform relevant tasks with cybersecurity risks in mind
- PR.PS Platform Security
NICE Framework
- DD-WRL-004 Secure Systems Development
- IO-WRL-005 Systems Administration