Infracost + Atlantis — automatic cost estimation in PR.
atlantis.yaml:
1version: 32projects:3 - name: infrastructure4 dir: infrastructure5 workspace: default6 autoplan:7 when_modified: ["*.tf", "*.tfvars", "atlantis.yaml"]8 enabled: true9 workflow: terraform-with-infracost1011workflows:12 terraform-with-infracost:13 plan:14 steps:15 - init16 - run: infracost diff --path $ATLANTIS_PROJECT_DIR --format json --out infracost.json17 - run: infracost comment github --path infracost.json --repo $ATLANTIS_GIT_CLONE_URL --pull-request $ATLANTIS_PULL_NUM --behavior update18 - plan:19 extra_args: ["-lock=false"]20 apply:21 steps:22 - apply
Infracost usage file (custom pricing):
1version: 0.12usage:3 aws_instance.web:4 operating_system: linux5 monthly_hrs: 7306 aws_s3_bucket.data:7 storage_gb: 1008 standard:9 monthly_tier_1_requests: 1000010 monthly_tier_2_requests: 1000
PR comment example:
🪙 Infracost estimate: monthly cost will increase by $12.41 (+8.5%)
| Product | Current | Change | New |
|------------------------|----------|---------|----------|
| aws_instance.web | $8.47 | +$3.94 | $12.41 |
| aws_s3_bucket.data | $0.00 | +$2.30 | $2.30 |
| TOTAL | $8.47 | +$6.24 | $14.71 |
Pros: Cost visibility in every PR, automatic comparison, guardrails (block expensive resources).