drift
On a schedule, drift plans every provisioned instance that matches a set of attributes, reads each plan's logs for changes, and alerts Slack about drift. It can remove the drift by re-applying the configuration that is deployed. It writes each result to the stash.
How a check runs​
The check lists the
PROVISIONEDinstances whose effective attributes matchmatch.For each instance, it reads the latest completed
PROVISIONdeployment and callsplanDeploymenton it. The plan uses the params of that deployment, not the instance's saved params, so unsaved and undeployed edits do not show up as drift. It skips an instance with a deployment that is pending, approved, or running, and an instance with no completedPROVISIONdeployment.Massdriver sends
deployment.completed,deployment.failed, ordeployment.abortedfor the plan. drift reads the plan's logs and gives the plan one result:Result When drifted A driftpattern match counts one or more changes.clean Every step has a cleanmatch, or adriftmatch with zero changes.unknown Fewer matches than the bundle has steps, for example a Helm step. failed The plan failed or was aborted, or no event came within 6 hours. It posts drifted, unknown, and failed results to Slack. The message has the change counts of each step, up to 20 lines of changed resources, and a link to the plan. Clean results are posted only with
notify_clean: true.For a drifted result,
modedecides what happens next. drift never resolves an unknown or failed result.
planDeployment plans the deployed params with the instance's current bundle version and dependencies. When the instance's resolved bundle version differs from the deployed version, or a dependency changed since the last provision, the plan also shows those changes. The alert names them, and drift does not resolve that instance.
Resolve modes​
mode | resolve_with: deployed (default) | resolve_with: saved |
|---|---|---|
detect (default) | Alert only. | Alert only. |
resolve | rollbackDeployment on the deployment that was planned, then approveDeployment on the proposal. | createDeployment PROVISION with the instance's saved params. |
propose | rollbackDeployment on the deployment that was planned. A person approves it. | proposeDeployment PROVISION with the instance's saved params. A person approves it. |
deployed re-applies only what was already deployed: the params, bundle version, and dependency snapshot of the last completed PROVISION. The saved params can hold edits that nobody deployed yet, and saved deploys those edits along with the drift fix.
rollbackDeployment pins the instance to the bundle version of the deployment it re-applies. Massdriver sets the message of a rollback to Rollback to deployment <id> (v<version>). A saved deployment has the message drift: <check> resolving drift found by plan <plan id>.
When the environment has separation of duty, the service account cannot approve its own rollback. The proposal stays open and the alert says to approve it in Massdriver.
With resolve or propose, a reply in the alert's thread says what drift did: the deployment it created, or why it did not create one. With only a webhook, the reply is a message of its own.
Results in the stash​
When a plan completes, drift writes two JSON entries:
| Key | Stash | Value |
|---|---|---|
md/v1/drift | The instance | {"status": "detected", "resources": 2, "checked_at": "2026-11-27T20:03:24Z"}. status is none, detected, or unknown. resources is the sum of the counts in the plan summaries. |
md/v1/changes/drift | The plan deployment | {"tool": "drift", "add": 0, "change": 1, "destroy": 1}, summed over the bundle's steps. Not written when the result is unknown, because some steps have no count. |
Entries in a deployment's stash are immutable: when Massdriver sends an event again, the first value stays. A failed write is logged at debug and never fails the event. The UI shows both keys as widgets. Refer to well-known keys. With results.prefix set outside md/, such as results/v1, each result shows as a labeled metadata row.
Settings​
The config file is YAML, at CONFIG_FILE (default /etc/massdriver-automations/config.yaml). An unknown key stops the automation at start. config.example.yaml has every key, with comments.
| Key | Default | |
|---|---|---|
slack.channel | The channel for alerts of checks that name no channel of their own. Without a channel or a webhook, alerts go to the logs only. | |
massdriver.app_url | https://app.massdriver.cloud | The Massdriver UI, for the plan links. |
results.prefix | md/v1 | The start of the stash result keys. |
checks[].name | Required. Unique. Alerts and POST /drift/run?check=<name> use it. | |
checks[].schedule | A cron expression (5 fields, or @daily, @hourly, @every 6h). Without one, the check runs only from POST /drift/run. | |
checks[].timezone | UTC | The IANA timezone of schedule. |
checks[].match | Effective attributes, such as md-environment: prod. A list matches any of its values. Keys are combined with AND. Empty matches every provisioned instance. | |
checks[].mode | detect | detect, resolve, or propose. |
checks[].resolve_with | deployed | deployed or saved. |
checks[].max_concurrent | 5 | Plans running at once for the check. The rest wait in a queue. |
checks[].slack.channel | slack.channel | The channel for this check's alerts. |
checks[].notify_clean | false | Post clean results. |
checks[].summary | false | Post one line of totals when a run finishes. |
checks[].patterns.clean | No changes\. | A Go (RE2) regular expression that marks a step with no changes. |
checks[].patterns.drift | Plan: \d+ to \w+(?:, \d+ to \w+)* | A Go regular expression that marks a step with changes. Each <n> to <verb> in the match is counted, so import and forget count too. |
checks[].patterns.resource | (?m)^\s*# \S+.* (?:will be\|must be) .*$ | A Go regular expression for the changed resource lines in the alert. |
slack:
channel: "#infra-drift"
checks:
- name: prod-nightly
schedule: "0 6 * * *"
timezone: America/Chicago
match:
md-environment: prod
team: [payments, billing]
mode: propose
resolve_with: deployed
slack:
channel: "#payments-oncall"
summary: true
- name: sandbox-weekly
schedule: "0 9 * * MON"
match:
md-project: sandbox
mode: resolve
resolve_with: saved
max_concurrent: 2
The bundle's Settings params have the keys of the config file, with these differences:
- A
matchvalue is one string. Separate values with commas, such asapi, web, to match any of them. The bundle writes it as a list. checks[].namemust be lowercase letters, numbers, and hyphens.checks[].match,mode, andresolve_withare required in the form, and the form starts with one check,prod-nightly, that alerts onmd-environment=prodat 06:00 UTC.
Run a check now​
curl -X POST -H "Authorization: Bearer $DRIFT_RUN_TOKEN" "https://drift.example.com/drift/run?check=prod-nightly"
The response is 202. A request for a check that does not exist gets 404.
Secrets​
| Variable | |
|---|---|
SLACK_BOT_TOKEN | The xoxb- token of the Slack app. Posts go to the channels in the settings. |
SLACK_WEBHOOK_URL | An incoming webhook, for a workspace without the Slack app. Every post goes to its one channel. Ignored when the bot token is set. |
DRIFT_RUN_TOKEN | Turns on POST /drift/run. Callers send it as Authorization: Bearer <token>. |
drift also reads STATE_DIR, a directory for the plans in progress and the queues (drift.json). The bundle sets it to a volume. The MASSDRIVER_* variables are in the common settings.
Permissions​
| Mode | Permissions on the matched instances |
|---|---|
| every mode | project:view on their projects, instance:plan, and stash:write |
resolve, deployed | instance:propose and instance:deploy |
resolve, saved | instance:deploy |
propose | instance:propose |
Deployed with the bundle, the service account also needs organization:manageEventDestinations.
Host​
The bundle serves drift at Ingress > Host, such as drift.automations.acme.com. On ECS, an empty host uses drift.<domain of the cluster's hosted zone>. /hooks/massdriver must be public, and /drift/run too to start checks from outside the cluster.
State storage (GiB) sizes the Kubernetes volume for STATE_DIR. On ECS, the state is on EFS. Refer to Deploy.
Event destination​
The bundle creates a destination for deployment.completed, deployment.failed, and deployment.aborted, with the condition .data.metadata.deployment_action == "PLAN" and the attributes of Event attributes.
To create it yourself, with mass 2.6.0 or later:
mass event destination create \
--name drift \
--url https://drift.example.com/hooks/massdriver \
--event-type deployment.completed \
--event-type deployment.failed \
--event-type deployment.aborted \
--condition '.data.metadata.deployment_action == "PLAN"'
The condition drops PROVISION and DECOMMISSION deployments, so Massdriver marks them SKIPPED and does not send them. drift ignores plans that it did not start.
Copy the signing secret from the destination's Overview tab into MASSDRIVER_SIGNING_SECRET.
Run​
docker run -p 8080:8080 \
-v "$PWD/config.yaml:/etc/massdriver-automations/config.yaml:ro" \
-v "$PWD/state:/state" \
-e MASSDRIVER_ORGANIZATION_ID=acme \
-e MASSDRIVER_API_KEY=md_... \
-e MASSDRIVER_SIGNING_SECRET=whsec_... \
-e SLACK_BOT_TOKEN=xoxb-... \
-e DRIFT_RUN_TOKEN=... \
-e STATE_DIR=/state \
ghcr.io/massdriver-cloud/massdriver-automations:0.3 run drift
The image runs as user 65532. That user must be able to write to STATE_DIR.
Limits​
- The API has no structured plan summary, so the result comes from log patterns. Output-only changes and provisioners other than OpenTofu and Terraform give
unknownunless you setpatterns. - The logs do not name their step. Matches are given step names in log order.
- Run one replica. The schedule and the plans in progress live in one process.
- Without
STATE_DIR, a restart forgets the plans in progress and the queues. Their results are not read. - A plan that finishes before drift records its id is not read.