100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Terraform & Infrastructure as Code
30 minintermediate

Drift Detection and Importing Resources

In a perfect world, all infrastructure changes go through Terraform. In reality, every production environment eventually diverges from its Terraform configuration: a developer manually adjusts an EC2 security group to debug a production incident, a cloud console change updates an RDS parameter group to fix a performance crisis, or a cloud provider automatically adds new default settings to existing resources. This divergence between what Terraform's state file expects and what actually exists in the cloud is called configuration drift. Left undetected, drift causes `terraform apply` to generate unexpected changes on the next run — overwriting the manual fix, or worse, creating a conflict that blocks future applies entirely. Terraform's `terraform refresh` command and `terraform plan -refresh-only` provide drift detection, while `terraform import` solves the complementary problem of bringing existing manually-created infrastructure under Terraform management. Both capabilities are essential operations skills for any team managing infrastructure at scale.

Analogy🏏Cricket
🏏 Think of it like cricket: Before standardised cricket rulebooks existed, every ground played by its own local customs — different LBW interpretations, different wide-ball rules, inconsistent DRS protocols. A touring team playing in a new city had to learn an entirely different set of rules. The standardised ICC rulebook is IaC: a version-controlled document that specifies exactly how cricket is played anywhere in the world. When any ground host asks 'how should this match be set up?', they apply the rulebook — not their memory, not local tradition, not a wiki page from 2019. Every ground becomes reproducible because they're all applying the same version-controlled specification. The insight is that codifying rules enables consistency at scale — you can run a thousand simultaneous cricket matches and every one follows the same rules because they all reference the same canonical document.
Lesson 21 of 24
0% complete