A CLI tool that runs opinionated quality checks on your IaC codebase.
Check the IaC guild guidelines for more information on the quality checks.
ℹ️ If you use Linux, you can install Linuxbrew
brew tap padok-team/tap
brew trust padok-team/tap
brew install guacamoleDownload and install the latest binary on Linux or macOS in one command:
OS=$(uname -s | tr '[:upper:]' '[:lower:]') \
ARCH=$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/') \
VERSION=$(curl -fsSL https://api.github.com/repos/padok-team/guacamole/releases/latest | grep tag_name | cut -d '"' -f 4) \
&& curl -fsSL "https://github.com/padok-team/guacamole/releases/download/${VERSION}/guacamole_${VERSION#v}_${OS}_${ARCH}.tar.gz" \
| tar -xz -C /tmp guacamole \
&& sudo install /tmp/guacamole /usr/local/bin/guacamoleTo install a specific version, replace the VERSION=... line with VERSION=v0.3.4 for example. Windows archives (.zip) are available on the releases page.
Verify the install:
guacamole versionPrerequisites :
- Golang
- Terraform
- Terragrunt
One-liner installer (in /tmp) :
DIR=$(pwd) cd /tmp && git clone git@github.com:padok-team/guacamole.git && cd guacamole && go build && alias guacamole=/tmp/guacamole/guacamole && cd $DIRFor a more permanent installation, just move the /tmp/guacamole/guacamole binary into a directory present in your $PATH.
The published Docker image includes the Terraform and Terragrunt versions defined in .tool-versions.
To test Guacamole with different CLI versions, build a custom image:
docker build \
--build-arg TERRAFORM_VERSION=x.y.z \
--build-arg TERRAGRUNT_VERSION=x.y.z \
-t guacamole:custom .Run Guacamole with Docker:
IMAGE=ghcr.io/padok-team/guacamole
TAG=latest
docker run --rm -v "$(pwd):/iac-repo" "${IMAGE}:${TAG}" <guacamole-cmd> -p /iac-repoThree modes currently exist :
-
Static mode : runs quality checks on the codebase without running Terraform / Terragrunt commands
guacamole static -p /path/to/your/codebase
-
[EXPERIMENTAL] State mode : runs quality checks based on your layers' state
We recommend using this command after checking that your codebase has been initialized properly.
guacamole state -p /path/to/your/codebase
-
[EXPERIMENTAL] Profile mode : creates a detailed report of the contents of your codebase
We recommend using this command after checking that your codebase has been initialized properly.
guacamole profile -p /path/to/your/codebase
-
CI mode: detects changed Terraform/Terragrunt directories from your Git diff (layers under
layers/, modules underbase/,functional/ormodules/), runs scoped static checks and can post a GitLab MR or GitHub PR comment.guacamole ci
The platform is detected automatically: GitHub when
GITHUB_ACTIONS=true, GitLab otherwise.Required CI environment:
GUACAMOLE_DIFF_BASE_BRANCH,CI_MERGE_REQUEST_TARGET_BRANCH_NAME(GitLab) orGITHUB_BASE_REF(GitHub)- Optional
GUACAMOLE_MR_SHA(defaults toHEAD) - Optional
GUACAMOLE_PROJECT_DIR,CI_PROJECT_DIR(GitLab) orGITHUB_WORKSPACE(GitHub) (defaults to current directory)
The Git history must contain the base branch: on GitHub, use
fetch-depth: 0withactions/checkout. Paths are relative to the project directory, which can be a sub-directory of the repository.Optional behaviour:
GUACAMOLE_CI_COMMENT=falseto disable comment postingGUACAMOLE_CI_SCAN_ALL=trueto scan every tracked layer/module instead of the changed ones (no base branch needed)GUACAMOLE_CI_FAIL_ON_ERROR=falseto exit with code 0 even when checks fail
To post a GitLab MR comment, ensure these variables are set:
CI_MERGE_REQUEST_IIDCI_API_V4_URLCI_PROJECT_IDGUACAMOLE_GITLAB_TOKEN
To post a GitHub PR comment, ensure these variables are set (the comment is updated in place on each run):
GITHUB_REPOSITORYandGITHUB_EVENT_PATH(set by GitHub Actions), orGUACAMOLE_GITHUB_PR_NUMBERto target a PR explicitlyGUACAMOLE_GITHUB_TOKENorGITHUB_TOKEN, with thepull-requests: writepermission- Optional
GITHUB_API_URL(defaults tohttps://api.github.com, useful for GitHub Enterprise Server)
On GitHub, the report is also written to the job summary and the
score,passedandtotalstep outputs are set. See Run in CI for ready-to-use configurations.
A verbose mode (-v) exists to add more information to the output.
Use the guacamole-action with check_type: ci to post the IaC score of the layers/modules changed by a pull request as a PR comment, updated in place on each push:
on:
pull_request:
permissions:
contents: read
pull-requests: write
jobs:
guacamole:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
with:
# The base branch history is needed to compute the diff
fetch-depth: 0
- name: Run guacamole
uses: padok-team/guacamole-action@v2
with:
check_type: ci
# Pull requests opened from a fork get a read-only token: skip the comment for them
comment: ${{ github.event.pull_request.head.repo.full_name == github.repository }}The action also supports scan_all, fail_on_error, base_branch and the other checks (static, state...): see its README and examples.
guacamole:
stage: test
image:
name: ghcr.io/padok-team/guacamole:v0.4.0
entrypoint: [""]
script:
- guacamole ci
rules:
- if: $CI_MERGE_REQUEST_IIDSet GUACAMOLE_GITLAB_TOKEN (access token with the api scope) in the project CI/CD variables to post the MR comment, or GUACAMOLE_CI_COMMENT=false to skip it.
You can use inline code comments to skip individual checks for a particular resource.
To skip a check on a given Terraform definition block resource, apply the following comment pattern inside its scope: # guacamole-ignore:<check_id> <suppression_comment>
- <check_id> is one of the available check scanners.
- <suppression_comment> is an optional suppression reason.
Example:
The following comment skips the TF_NAM_001 check on the resource identified by network
# guacamole-ignore:TF_NAM_001 We will be creating more rg
resource "azurerm_resource_group" "network" {
name...You can also whitelist entire checks in modules by adding them to a .guacamoleignore file at the root of your codebase.
The format of the file should be: path of the module - check ID to ignore.
pathtomodule/modules/cloud-run-app TF_MOD_002,TF_MOD_001
pathtomodule/modules/network TF_NAM_001
This is the only way to whitelist the check TF_MOD_002
You can specify the path of the .guacamoleignore file with the -w flag.
TF_MOD_001- Remote module call should be pinned to a specific versionTF_MOD_002- Provider should be defined by the consumer of the moduleTF_MOD_003- Required provider versions in modules should be set with ~> operatorTF_NAM_001- Resources in modules should be named "this" or "these" if their type is uniqueTF_NAM_002- snake_case should be used for all resource namesTF_NAM_003- Stuttering in the naming of resourcesTF_NAM_004- Variable name's number should match its typeTF_NAM_005- Resources and data sources should not be named "this" or "these" if there are more than 1 of the same typeTF_VAR_001- Variable should contain a descriptionTF_OUT_001- Output should contain a descriptionTF_VAR_002- Variable should declare a specific typeTF_DAT_001- Data source should not depend on a value computed during applyTF_QUA_001- Terraform code should be properly formatted usingterraform fmt
TG_DRY_001- No duplicate inputs within a layerTG_DRY_002- A local should only be defined if it is reused (DRY) or abstracts complexityTG_ARC_001- terragrunt.hcl should be the last file in the layerTG_INP_001- Terragrunt inputs should match variables declared in the called moduleTG_QUA_001- Terragrunt code should be properly formatted usingterragrunt hcl format
