Automate
CI and pipelines
Infraglass fits into a pipeline without changing it. Run Terraform as you do today, then give the
plan (and, optionally, the recorded apply) to infraglass check. It writes reports, prints a short
summary, and fails the step only on the gates you choose.
infraglass check
terraform plan -out=tfplan
infraglass check --plan-file tfplan \
--fail-on stateful-change,failed-check,high-risk \
--json report.json --markdown report.md --html report.html
Gates (--fail-on)
| Gate | Fails when |
|---|---|
high-risk |
there's any high-severity risk |
risk |
there's any medium or high risk |
stateful-change |
a resource that holds data (database, bucket, table, key, volume, queue, secret, log group and similar) is replaced or deleted |
delete |
anything is deleted or replaced |
high-finding |
there's any high-severity access or exposure finding |
finding |
there's any medium or high finding |
drift |
Terraform found a resource changed outside it |
failed-check |
a precondition, postcondition, check block or validation failed or errored |
failed-run |
an included recorded run (--run) failed |
Exit status
| Status | Meaning |
|---|---|
| 0 | done; every gate passed (or none was given) |
| 1 | an error, such as unreadable input |
| 2 | a usage error, such as an unknown gate |
| 3 | a gate failed; the reports are still written |
The JSON contract: infraglass.report/v1
check --json and export --format json write the same document. Within v1, fields are only ever
added. Attribute values are left out: changes and drift carry attribute paths only.
| Field | Contents |
|---|---|
schema |
"infraglass.report/v1" |
generated, tool |
when, and which Infraglass version |
source |
kind (state or plan), label, terraform_version |
summary |
counts: resources, data_sources, modules, actions, risks, findings, drifted, checks |
changes[] |
address, type, module, action, reason, attributes, forces_replacement, dependents |
risks[] |
severity, kind, address, message |
findings[] |
address, severity, rule, message, path, statement |
drift[] |
address, action, attributes |
checks[] |
address, kind, status, problems |
runs[] |
id, status, operation, seconds, summary, failed, and for plans an outcome: counts (planned, applied, failed, incomplete, in_progress, not_attempted, unplanned) and a result per resource (applied, failed, incomplete, in-progress, not-attempted, unplanned). incomplete is a change that started but never finished in a run that ended, such as a replace whose destroy ran and whose create didn't |
gate |
with check: fail_on, passed, failed (the gates that failed), reasons |
infraglass compare --format json A B writes infraglass.compare/v1, with added, removed,
changed (with attribute paths and masked values) and unchanged.
GitHub Actions
The repository is also an Action. It installs a release (checking the checksum and the signed
build provenance), runs check, writes the job summary, keeps one comment on the pull request up
to date, uploads the HTML, JSON and Markdown reports, and fails only on your gates.
name: Terraform review
on: pull_request
permissions:
contents: read
pull-requests: write # for the comment
id-token: write # only if your Terraform uses OIDC to reach the cloud or backend
jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: hashicorp/setup-terraform@dfe3c3f87815947d99a8997f908cb6525fc44e9e # v4.0.1
with:
terraform_wrapper: false
- run: terraform init -input=false
- run: terraform plan -input=false -out=tfplan
- uses: ityashag/infraglass@a986fa72abbd3a3458944d9b17784c7d07a1a492 # v0.2.3
with:
plan-file: tfplan
version: v0.2.3
fail-on: stateful-change,failed-check,high-finding
Pin every action to a full commit SHA, as above: a tag can be moved, a commit can't. To start
without blocking anyone, leave out fail-on; the comment and reports work the same. A complete
starter workflow is on Trying it on real pull requests.
| Input | Default | |
|---|---|---|
working-directory |
. |
Terraform directory for plan-file or the current state |
plan-file / plan / state |
a saved plan, or saved JSON | |
run |
a recorded stream or runs directory to include | |
fail-on |
none | gates, comma-separated |
comment |
true |
post or update one PR comment |
artifact-name |
infraglass-report |
empty to skip the upload |
version |
latest |
which release to install |
install |
true |
false to use an infraglass already on PATH |
github-token |
github.token |
token for the release download and the comment |
Outputs: passed, json, markdown, html (file paths).
To include the apply, record it with infraglass record and pass the file. The Action keeps its
own copy of infraglass off the PATH, so install one for record first:
- name: Install infraglass for record
env:
GH_TOKEN: ${{ github.token }}
FILE: infraglass_0.2.3_linux_amd64.tar.gz
run: |
mkdir -p "$RUNNER_TEMP/ig" && cd "$RUNNER_TEMP/ig"
gh release download v0.2.3 -R ityashag/infraglass -p "$FILE" -p checksums.txt
grep " $FILE\$" checksums.txt | sha256sum -c -
tar xzf "$FILE" infraglass
echo "$RUNNER_TEMP/ig" >> "$GITHUB_PATH"
- run: terraform apply -input=false -json tfplan | infraglass record runs/apply.jsonl
- uses: ityashag/infraglass@a986fa72abbd3a3458944d9b17784c7d07a1a492 # v0.2.3
if: ${{ !cancelled() }} # report a failed apply too
with:
plan-file: tfplan
run: runs/apply.jsonl
fail-on: failed-run
install: false
GitLab CI
terraform-review:
image:
name: hashicorp/terraform:1.9
entrypoint: [""] # the image's entrypoint is terraform; GitLab needs a shell
variables:
IG_VERSION: "0.2.3"
script:
- terraform init -input=false
- terraform plan -input=false -out=tfplan
- IG_FILE="infraglass_${IG_VERSION}_linux_amd64.tar.gz"
- wget -q "https://github.com/ityashag/infraglass/releases/download/v${IG_VERSION}/${IG_FILE}"
"https://github.com/ityashag/infraglass/releases/download/v${IG_VERSION}/checksums.txt"
- grep " ${IG_FILE}\$" checksums.txt | sha256sum -c -
- tar xzf "$IG_FILE" infraglass
- ./infraglass check --plan-file tfplan --fail-on stateful-change,failed-check
--json report.json --markdown report.md --html report.html
artifacts:
when: always
paths: [report.json, report.md, report.html]
Post report.md as a merge-request note with your usual tool (for example the GitLab API and a
project token).
Jenkins
Install infraglass on the agent first, the same way as on your machine (see
Getting started), or use the Docker image with saved JSON.
stage('Terraform review') {
steps {
sh 'terraform plan -input=false -out=tfplan'
sh 'infraglass check --plan-file tfplan --fail-on stateful-change,failed-check --json report.json --html report.html'
}
post {
always { archiveArtifacts artifacts: 'report.*' }
}
}
A non-zero status fails the stage: 3 means a gate tripped, and the reports are already written.
Any other system works the same way: run the CLI, read the exit status, and keep or parse
report.json.
Credentials
Infraglass needs none of its own. --plan-file and --dir run terraform show, which reads the
state through your backend with the credentials your pipeline already gives Terraform. With saved
JSON (--plan, --state), no credentials are involved at all.