Drift Detection

One of the main challenges when managing infrastructure as code is drift.
Drift means that the real-world state of your resources is different than your actual code. This can happen if someone is adding, updating or removing resources manually or with some automation tools outside of your Terraform code.

env0 can help you detect those drifts and alert you about them automatically by combining a few features together. If you would like to set up a drift detection on your environment and get notified if a drift occurred you will need to follow these steps:

  1. Enable Skip Apply Step: Enable this feature, in the "project settings" > "policies" tab. This will skip the apply phase when no changes were detected in the plan phase. In other words, if there is no drift, env0 will not apply those changes and will not require a user approval. You can read more about this feature here.
  1. Disable Approve plan automatically: Make sure your environment is deployed without enabling the "Approve plan automatically" checkbox. To verify the intended behavior, redeploy your environment and set this checkbox to the appropriate setting.
  1. Schedule a deployment: In the environment triggers tab, under scheduling make sure you add a deployment schedule using cron expressions based on the interval you would like to check the drift. For example if you would like to check the drift twice a day at 10AM and at 7PM enter 00 10,19 * * * in the deploy schedule. You can read more about this feature here.
  1. Add Slack/Teams Notification: To get notified directly in Slack or Microsoft Teams when a drift has been detected, set up notifications targets on your project settings under Notifications.
    Make sure you check the "Waiting for approval" event, and now whenever a drift has been detected you will get notified. You can read more about this feature here.

Did this page help you?