Learn to scan Azure resources for cost governance violations using PSRule, Checkov, Cloud Custodian, and Infracost.
View the Project on GitHub devopsabcs-engineering/finops-scan-workshop
| Duration | 35 minutes |
| Level | Intermediate |
| Prerequisites | Lab 01 |
By the end of this lab, you will be able to:
infracost breakdown to estimate monthly infrastructure costs from Bicep templatesinfracost diff to compare cost changes between Bicep revisionsinfracost-to-sarif.py converterYou will set up Infracost with an API key and review the project configuration.
Register for a free Infracost API key at infracost.io if you have not already.
Configure the API key:
infracost configure set api_key YOUR_API_KEY
Verify the configuration:
infracost configure get api_key
Open src/config/infracost.yml and review the project configuration:
version: 0.1
projects:
- path: infra/
name: finops-demo-app
This tells Infracost to scan the infra/ directory within each demo app for Bicep or Terraform templates.

[!TIP] Infracost uses cloud pricing APIs to estimate costs. It does not require deployed resources — it analyses IaC templates and maps resource types to current pricing data. This makes it ideal for pre-deployment cost checks in CI/CD pipelines.
You will generate a cost breakdown for the oversized resources demo app.
Create the reports directory:
mkdir -p reports
Run the Infracost breakdown against app 002:
infracost breakdown --path finops-demo-app-002/infra/ --format json --out-file reports/infracost.json
View the human-readable summary:
infracost breakdown --path finops-demo-app-002/infra/
The table output shows each resource, its SKU or tier, and the estimated monthly cost.
reports/infracost.json and review the structure:
projects — array of scanned IaC pathstotalMonthlyCost — total estimated monthly cost across all resourcesresources — individual resource cost breakdowns with line-item pricing
[!NOTE] App 002 uses a P3v3 App Service Plan and Premium storage. These are expensive tiers intended for production-grade workloads. Infracost makes the monthly cost immediately visible so you can make informed decisions before deploying.
You will modify a SKU in app 002’s Bicep template and use infracost diff to see the cost impact.
Open finops-demo-app-002/infra/main.bicep in your editor.
Find the App Service Plan SKU and change it from P3v3 to B1 (Basic tier):
// Before:
// sku: { name: 'P3v3', tier: 'PremiumV3' }
// After:
sku: { name: 'B1', tier: 'Basic' }
Run infracost diff to compare the cost of the modified template against the baseline:
infracost diff --path finops-demo-app-002/infra/ --compare-to reports/infracost.json
The diff should show a significant cost reduction from downgrading P3v3 to B1 — this demonstrates why right-sizing matters for FinOps governance.
Revert the change to main.bicep so it does not affect later labs:
git checkout finops-demo-app-002/infra/main.bicep

[!IMPORTANT] Always revert intentional Bicep changes after completing this exercise. The demo apps are designed with specific violations, and modifying them permanently can affect Labs 06 and 07.
You will convert the Infracost JSON output to SARIF format.
Run the SARIF converter:
python src/converters/infracost-to-sarif.py reports/infracost.json reports/infracost.sarif
Open the generated SARIF file:
cat reports/infracost.sarif
tool.driver.name is set to infracost-to-sarifmessage.text includes the estimated monthly cost for the resourcephysicalLocation points to the Bicep file that defines the resource
You will walk through the GitHub Actions workflow that blocks expensive infrastructure changes in pull requests.
Open .github/workflows/finops-cost-gate.yml and review the workflow structure:
name: FinOps Cost Gate
on:
pull_request:
branches: [main]
paths: ['infra/**']
The workflow triggers on pull requests to main that modify files under infra/.
infracost breakdown to capture the current costinfracost comment github to add a cost summary comment to the PRNote the infracost comment github command:
infracost comment github \
--path infracost-output.json \
--repo $ \
--pull-request $ \
--github-token $ \
--behavior update
The --behavior update flag updates the existing comment instead of creating duplicates on each push.

[!TIP] In production, you can extend the cost gate to fail the PR check if costs exceed a threshold. Add a step that reads
totalMonthlyCostfrom the Infracost JSON and compares it against a budget limit.
Before proceeding, verify:
infracost diff after modifying a SKUProceed to Lab 06 — SARIF Output and GitHub Security Tab.