Detecting Terraform state drifts with Driftive

Detecting Terraform state drifts with Driftive
Photo by Benjamín Gremler / Unsplash

Infrastructure as Code (IaC) projects using Terraform/OpenTofu/Terragrunt often experience state drifts over time. These drifts might not seem significant initially, but as your infrastructure evolves, they can hinder your team's ability to make changes efficiently.

Understanding State Drift

State drift occurs when the real-world state of your infrastructure diverges from the state defined in your Terraform configuration files. Despite best practices dictating that all infrastructure changes should be made through Terraform, there are instances where modifications happen outside of Terraform. Detecting and addressing these discrepancies is crucial to maintaining the integrity of your infrastructure.

Introducing Driftive

To tackle this challenge, I developed Driftive—a tool designed to detect state drifts in Terraform/Terraform/OpenTofu projects. Driftive simplifies the process by scanning a specified root directory for projects and checking if the plan identifies any changes.

How Driftive Works:

  1. Input Directory: You provide Driftive with a root directory.
  2. Project Detection: Driftive searches for projects within this directory.
  3. Plan Check: Driftive runs the terragrunt/tofu/terraform plan command to identify any changes that indicate a state drift.
Driftive example

Automating Drift Detection with GitHub Actions

To further streamline the process, Driftive can be integrated with GitHub Actions. This allows you to set up a workflow that runs periodically, automatically detecting state drifts and sending notifications to your Slack channel.

Conclusion

By integrating Driftive into your infrastructure management process, you can proactively detect and address state drifts, ensuring your IaC projects remain consistent with your real-world infrastructure. This definitely will enhance your team's efficiency.