Catch destructive Terraform applies before approval

Every 30 minutes we check the Terraform runs waiting for approval and post a Slack warning whenever an apply would delete or recreate your resources.

Agentic Task
HCP Terraform (Terraform Cloud)Slack BotEngineeringNotifications & Alerts
PromptCreate

Every 30 minutes during business hours on weekdays, act as a pre-apply safety guardrail for our HCP Terraform (Terraform Cloud) infrastructure. This runs on a schedule (not on the new-run event) on purpose: a run's plan JSON is not ready to read the moment a run is queued, so scanning on a cadence for runs that are already in the planned state guarantees the plan is finished and readable before anyone approves the apply.

For each workspace we manage, use HCP Terraform's List Workspace Runs with status filtering to find runs that are planned and awaiting confirmation, meaning they have finished planning and are now waiting for a human to approve or discard the apply. Ignore runs in any other state.

For every such pending run, pull the Get Plan JSON Output and scan the plan's resource_changes. Look at each change's actions array: a change is destructive when it contains a delete, or a replace (a create and delete pair, shown as ["create", "delete"] or ["delete", "create"]). Changes that only create (add) or update (change in place) resources are safe. Use Show Run if you need the run's details or a link to it.

When a pending run will destroy or recreate one or more resources, post a prominent warning to our infrastructure Slack channel using the Slack Bot Send a Message action. Send one clear message per risky run that names the workspace, lists exactly which resource addresses are set to be destroyed and which are set to be replaced, and includes a link to the run so a reviewer can inspect it before approving. Make the destructive resources impossible to skim past.

Flag anything touching databases, storage buckets, or other stateful resources as HIGH RISK at the top of the message, since destroying or replacing those can mean permanent data loss. Treat resource types such as managed database instances and clusters (for example RDS, Cloud SQL, Aurora), object storage buckets (for example S3, GCS, Azure Blob), persistent volumes and disks, and stateful data stores as high risk.

Stay completely silent when a pending plan only adds or updates resources: send no message at all, so the channel stays high signal and people trust every alert. This is a pre-apply safety review guardrail, separate from any daily run digest, so the only thing that ever reaches Slack is a genuinely risky pending apply.

Additional information

What does this prompt do?
  • Checks your Terraform workspaces every half hour for runs that are planned and waiting for someone to approve the apply.
  • Reads what each pending run would actually do and spots any resource that would be destroyed or recreated.
  • Posts a clear warning to your infrastructure Slack channel that names the workspace, lists the at-risk resources, and links straight to the run.
  • Stays quiet when a run only adds or updates things, and flags databases and storage as high risk so nobody loses data by accident.
What do I need to use this?
  • An HCP Terraform (Terraform Cloud) account with the workspaces you want watched.
  • A Slack workspace and a channel where your infrastructure team gets alerts.
  • Permission for the bot to read your Terraform runs and post to that channel.
How can I customize it?
  • Change how often it checks, or limit it to your team's working hours.
  • Point it at a different Slack channel, such as a dedicated incident or on-call channel.
  • Adjust what counts as high risk, for example adding message queues or DNS records alongside databases and storage.

Frequently asked questions

Will this approve or reject the apply for me?
No. It only warns you. It reads the runs that are waiting for approval and posts a Slack message so a human can decide. Approving or discarding a run stays entirely in your hands inside HCP Terraform.
Does it message me for every Terraform run?
No. It stays silent when a run only adds or updates resources. You only get pinged when something would be destroyed or recreated, so the channel stays low noise and every alert is worth reading.
How does it know a change is risky?
It reads the planned changes for each pending run and looks for anything set to be deleted or replaced. Replacements are risky because they destroy the old resource and create a new one, which can wipe data on databases and storage.
Why every 30 minutes instead of the moment a run starts?
A run's plan is not ready to read the instant it is queued. Checking on a schedule makes sure the plan has finished, so it can see exactly what would change before anyone approves the apply.
Can I use this with only part of my infrastructure?
Yes. You can point it at specific workspaces and a single channel, and tune which resource types count as high risk to match how your team works.

Stop risky Terraform applies before they destroy data.

Get a Slack warning the moment a pending run would delete or recreate your infrastructure, so no one rubber-stamps a dangerous apply.