CI/CD Integration
Add automatic cost estimation to every pull request. C3X integrates with all major CI/CD platforms. Each example below includes the install step, estimate step, comment step, and a budget gate.
GitHub Actions
Add cost estimation to every pull request with two steps. No API key or secrets required.
name: Cost Estimation
on: [pull_request]
permissions:
pull-requests: write
contents: read
jobs:
c3x:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: c3xdev/setup-c3x@v1
with:
path: .Branded PR Comments
Install the C3X Cloud GitHub App on your repository. Once installed, PR comments automatically appear as C3X Cloud with the C3X logo instead of the generic github-actions bot. No secrets or additional configuration needed.
GitLab CI
Add a cost-estimation stage to your .gitlab-ci.yml.
stages:
- validate
- cost-estimation
- plan
- apply
cost-estimation:
stage: cost-estimation
image: alpine:latest
before_script:
- apk add --no-cache curl tar
- curl -fsSL https://github.com/c3xdev/c3x/releases/latest/download/c3x-linux-amd64.tar.gz |
tar -xz -C /usr/local/bin c3x
script:
- c3x estimate --path . --format json --out-file c3x.json
- c3x comment gitlab --path . --gitlab-token $GITLAB_TOKEN
- c3x estimate --path . --budget 5000
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"Set the GITLAB_TOKEN variable in Settings > CI/CD > Variables. The token needs the api scope to write merge request comments.
Bitbucket Pipelines
Add a cost estimation step to your bitbucket-pipelines.yml.
pipelines:
pull-requests:
'**':
- step:
name: Cost Estimation
image: alpine:latest
script:
# Install C3X
- apk add --no-cache curl tar
- curl -fsSL https://github.com/c3xdev/c3x/releases/latest/download/c3x-linux-amd64.tar.gz |
tar -xz -C /usr/local/bin c3x
# Run estimate
- c3x estimate --path . --format json --out-file c3x.json
# Post PR comment
- c3x comment bitbucket --path . --bitbucket-token $BITBUCKET_TOKEN
# Budget gate
- c3x estimate --path . --budget 5000Add BITBUCKET_TOKEN as a repository or workspace variable. The token needs read and write access to pull requests.
Azure Pipelines
Add a cost estimation job to your azure-pipelines.yml.
trigger: none
pr:
branches:
include:
- main
pool:
vmImage: ubuntu-latest
steps:
- checkout: self
- script: |
curl -fsSL https://github.com/c3xdev/c3x/releases/latest/download/c3x-linux-amd64.tar.gz | \
tar -xz -C /usr/local/bin c3x
displayName: Install C3X
- script: |
c3x estimate --path . --format json --out-file c3x.json
displayName: Estimate costs
- script: |
c3x comment azure-repos --path . --azure-access-token $(System.AccessToken)
displayName: Post PR comment
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
- script: |
c3x estimate --path . --budget 5000
displayName: Budget gateThe built-in System.AccessToken is used for PR comments. Ensure the build service account has Contribute to pull requests permission on the repository.
Atlantis
Run C3X as a custom workflow step in your atlantis.yaml (repo-level config). The cost estimate is posted as a comment alongside the Terraform plan.
version: 3
projects:
- dir: .
workflow: c3x
workflows:
c3x:
plan:
steps:
- init
- plan
- run: |
c3x estimate --path $PLANFILE --format table
- run: |
c3x estimate --path $PLANFILE --budget 5000Install C3X on the Atlantis server or use a custom Docker image that includes both Terraform and C3X. The $PLANFILE variable is set by Atlantis to point to the generated plan file.
Spacelift
Use C3X in a Spacelift before_apply hook to gate deployments on cost. You can also use before_plan to estimate costs before the plan runs.
# .spacelift/config.yml
version: "1"
before_plan:
- |
curl -fsSL https://github.com/c3xdev/c3x/releases/latest/download/c3x-linux-amd64.tar.gz | \
tar -xz -C /usr/local/bin c3x
after_plan:
- |
c3x estimate --path . --format json --out-file c3x.json
before_apply:
- |
c3x estimate --path . --budget 5000The before_apply hook acts as a budget gate: if the estimate exceeds the threshold, C3X exits with code 1 and the apply is blocked. Cost data from the JSON output can be sent to external dashboards using Spacelift notifications.
Tips
- Use
--format json --out-file c3x.jsonto save the estimate for downstream steps or artifact storage. - Use
--budgetfor absolute cost gates and--budget-increasefor incremental cost gates. - Provide a usage file for accurate estimates of variable-cost resources.
- For air-gapped CI environments, see the Self-Hosted & Offline guide.
- See the CLI Reference for the full list of flags available on each command.