Skip to content
🎉 Launch sale:50% off everything over $22 — automatically applied at checkout· ends Aug 2Shop the sale →
DevOps AI ToolKit
Newsletter
All prompts
AI for Terraform Difficulty: Intermediate ClaudeCopilot

Terraform Plan Cost Gate in CI Prompt

Add an automated cost-delta gate to a Terraform pipeline that blocks or flags pull requests whose plan increases monthly spend beyond a threshold.

Target user
Platform teams adding FinOps guardrails to Terraform CI
Difficulty
Intermediate
Tools
Claude, Copilot

The prompt

You are a senior platform engineer who builds FinOps guardrails into Terraform pipelines so cost-increasing changes are caught at review time, not on the invoice.

I will provide:
- The CI system (GitHub Actions, GitLab CI, etc.)
- The cost tool available (Infracost or equivalent)
- The policy I want (hard block vs warn, threshold amount)

Your job:

1. **Generate the plan safely** — run `terraform plan -out=tfplan` and `terraform show -json tfplan` as a read-only step using least-privilege, plan-only credentials.
2. **Compute the cost delta** — feed the plan JSON to the cost tool to produce a baseline-vs-proposed monthly diff, not just a total.
3. **Define the gate** — implement the policy: warn-only comment, soft threshold, or a hard failure above a configurable monthly-increase limit.
4. **Surface it to reviewers** — post the cost breakdown as a PR comment so the delta is visible alongside the plan.
5. **Handle edge cases** — account for usage-based resources the tool cannot price, free-tier items, and destroys that reduce cost.
6. **Allow overrides** — provide an auditable way to bypass the gate (label or approval) for justified increases.
7. **Keep it deterministic** — pin tool versions and cache pricing so the gate gives stable results.

Output as: (a) the pipeline job YAML, (b) the threshold/policy config, (c) the PR-comment format, (d) the override mechanism.

This gate runs only plan and read-only commands; never grant it apply permissions, and treat a cost spike as a signal to review the plan, not an excuse to skip it.

Run this prompt with AI

Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.

Related prompts

More Terraform prompts & error guides

Browse every Terraform prompt and troubleshooting guide in one place.

Free download · 368-page PDF

Reading prompts? Get all 500 in one free PDF

500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.

  • 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
  • Instant PDF download — yours free, forever
  • Plus one practical AI-workflow email a week (no spam)

Single opt-in · unsubscribe anytime · no spam.