Audit Every Agent Tool Call Against Policy Before It Goes Unnoticed
Replay a recorded agent run through denylist, allowlist and budget rules, escalate violations to GitHub and Slack, and publish the verdict.
Gate Terraform PRs on cloud cost — run Infracost for a monthly estimate, compare against your budget, and alert Slack and fail the build when over.
Cloud cost surprises are cheapest when they are still a pull request. This blueprint turns the monthly cost of a Terraform change into a CI signal: clone the IaC repository, run Infracost against the HCL — no terraform init, no cloud credentials, no apply — and compare the estimated monthly total with a budget input. Over the ceiling, Slack gets the estimate, the budget, and the percentage, and the execution fails so the CI check on the open pull request turns red. Under it, a quiet log keeps a cost trend in the execution history. It closes the gap between "the plan looks fine" and "the plan looks fine, and costs what we agreed".
on_iac_push trigger (io.kestra.plugin.core.trigger.Webhook) exposes a keyed URL for your CI to POST to on push or pull-request events.workspace (io.kestra.plugin.core.flow.WorkingDirectory) opens one shared filesystem for the checkout, the estimate, and the report parser.clone_repository (io.kestra.plugin.git.Clone) checks out repository_url at branch; public repositories need no credentials, private ones take a username and token on the task.run_cost_estimate (io.kestra.plugin.scripts.shell.Commands on the io.kestra.plugin.scripts.runner.docker.Docker runner, image infracost/infracost:latest) runs infracost breakdown --path <iac_path> --format json into infracost-report.json, authenticated with the INFRACOST_API_KEY secret. Infracost parses the HCL directly, so the estimate never touches a cloud account.parse_estimate (io.kestra.plugin.scripts.python.Script on the Process runner) extracts the total monthly cost tolerantly (wrapped breakdown, top-level, or summed projects), computes pct_of_budget, and raises if the report is unreadable — a broken gate must never look like a cheap change.check_budget (io.kestra.plugin.core.flow.If) branches on over_budget. Over: alert_over_budget posts the numbers to Slack and fail_the_build (io.kestra.plugin.core.execution.Fail) turns the CI check red. Under: log_within_budget records the pass.errors block alerts Slack when the gate itself fails, naming the three things that usually break: API key, repository URL, path input.budget_check JSON output (estimate, budget, percentage, verdict) for dashboards and trend reporting.Infracost estimates cost but does not watch repositories, remember budgets, or fail builds. Kestra provides the loop around it: a webhook trigger from CI, a hermetic container for the tool, a branch that separates the gate verdict from the evidence, alert routing to Slack, and an execution history that doubles as a cost trend. The same logic in a CI script is a YAML blob nobody reviews, with no alerting when the script itself breaks.
parse_estimate to a Docker task runner.INFRACOST_API_KEY: Infracost API key used by the estimate container.COST_GATE_WEBHOOK_KEY: key segment guarding the webhook URL — treat it as a secret.SLACK_WEBHOOK_URL: Slack incoming webhook URL.repository_url, branch, and — for monorepos — iac_path to the Terraform root module you want estimated.budget_check from the outputs to see your estimate, then set budget_usd to the real ceiling.on: pull_request, GitLab pipeline, etc.) at /api/v1/{tenant}/executions/webhook/{namespace}/terraform-infracost-budget-gate/{COST_GATE_WEBHOOK_KEY} and treat a failed execution as a failed check.iac_path at a root module you know is over budget and confirm the Slack alert and the failed execution.username and password: "{{ secret('GIT_TOKEN') }}" to clone_repository.fail_the_build (or move it behind another If on a hard_gate input) to alert without failing.infracost diff --path . --compare-to <base> and gate on the delta instead of the absolute total.Parallel or Loop over a list of iac_path values and aggregate the totals.Schedule trigger alongside the webhook to estimate nightly regardless of pushes.