Cost Gates in CI/CD Pipelines
A CI/CD pipeline can enforce cost policies automatically on every change. This lesson explains the kinds of cost checks a pipeline can run, how to design gates that engineers accept, and how to implement policy checks against infrastructure plans.
Learning outcomes
After completing this lesson, you will be able to:
- Describe the cost and policy checks a pipeline can run.
- Distinguish inform, warn and block responses.
- Identify the features of gates that engineers accept.
- Interpret a simple policy check against a plan file.
- Explain how gate results are recorded as cost avoidance.
Checks in the pipeline
A continuous integration and continuous delivery (CI/CD) pipeline already runs tests, security scans and linting on every change. Cost checks fit naturally into the same pipeline, running on infrastructure changes after the plan is produced and before it is applied. They can check two kinds of things: the estimated cost change against thresholds, and policies such as required tags, allowed instance types, approved regions or lifecycle rules.
Inform, warn or block
A cost check can respond in three ways. The following terms describe them.
- Inform
- Report the estimate and any policy findings, for example as a pull request comment, without affecting the pipeline.
- Warn
- Flag the change for attention, for example by requiring an additional reviewer when the increase exceeds a threshold.
- Block
- Fail the pipeline, for example when a mandatory policy is violated or the increase exceeds a hard limit without approval.
Most organizations start with inform, add warn for large increases, and block only for clear policy violations, such as a missing owner tag or a disallowed region, where there is no legitimate reason to proceed.
The following diagram assigns a gate action to three example changes.

Inform, warn or block?
Designing gates engineers accept
A badly designed gate is quickly worked around: engineers split changes to stay below thresholds, apply changes outside the pipeline or demand that the gate be removed. The following list describes the features of gates that work.
- Clear, published thresholds that engineers know in advance, such as an increase above USD 1,000 a month or 20% of the service's cost.
- Fast feedback in the pull request, not hours later.
- An approval path for justified increases, such as approval by the product owner or a FinOps champion.
- Low false positives, tuned by reviewing which checks trigger and why.
- Clear messages that explain what triggered the check and how to resolve it.
A gate that teams bypass
Policy checks against the plan
Policy checks evaluate the plan's JSON against rules. Open Policy Agent, policy features of IaC platforms or a simple script can do this. The following Python fragment shows the idea: it reads a Terraform plan in JSON form and reports instances created without an owner tag.
import json, sys
plan = json.load(open("plan.json"))
problems = []
for change in plan.get("resource_changes", []):
if change["type"] == "aws_instance" and "create" in change["change"]["actions"]:
tags = (change["change"]["after"] or {}).get("tags") or {}
if "owner" not in tags:
problems.append(change["address"])
if problems:
print("Missing owner tag:", ", ".join(problems))
sys.exit(1)A non-zero exit code fails the pipeline step, which is how a check blocks a change. The hands-on lab for this module builds a fuller check that also estimates cost against a threshold.
Recording and learning
Gate results should be logged: which checks triggered, which were approved as exceptions and what cost was avoided. This data shows the FinOps team which policies matter, which thresholds need adjustment and how much cost the pipeline prevents. Cost avoided this way is cost avoidance, reported separately from realized savings.
A gate that teams bypass
A pipeline blocks any infrastructure change that increases estimated cost by more than USD 200 a month. After two months, several teams apply changes manually outside the pipeline. What should change?
The threshold is too low for routine growth, and there is no approval path, so the gate blocks legitimate work. The FinOps team should change it to inform on all changes, warn above a higher threshold relative to each service's cost, and allow approval by the product owner, keeping blocks for policy violations. Manual changes outside the pipeline should be prevented by permissions, because they also bypass security checks.
What to block
Which of these should a pipeline block: (a) a change that adds USD 3,000 a month for a planned capacity increase; (b) a new instance without an owner tag; (c) a GPU instance type in a production account where it is not on the approved list?
(a) should warn and require approval, because the increase may be justified. (b) should block, because a missing owner tag is a clear policy violation with an easy fix. (c) should block unless an exception has been approved, because the instance type is outside policy.
Which response suits a planned, justified cost increase above the threshold: inform, warn or block?
Show answer
Warn, with an approval path such as product owner sign-off. Blocking suits clear policy violations with no legitimate reason to proceed.
Exam Tips
Remember for the exam
- Pipelines can check estimated cost changes and policies such as tags and allowed types.
- Inform on everything, warn on large increases, block clear policy violations.
- Gates need clear thresholds, fast feedback, an approval path and low false positives.
- Log gate results; prevented cost is cost avoidance.