Toolkit: Terragrunt, Atlantis, Infracost, Checkov & More
The CLI, tflint and the test framework are the core. Around them is an ecosystem of tools that teams add as their infrastructure grows. None of these is in the course sandbox, so the sessions below are samples; every tool has good official documentation, and versions move fast, so check them before adopting.
Version managers: tenv
Different repositories need different CLI versions. tenv installs and switches OpenTofu, Terraform, Terragrunt and Atmos versions, picking the right one from files in the repository:
$ cat .opentofu-version
1.13.2
$ tenv tofu install # reads .opentofu-version
$ tofu version
OpenTofu v1.13.2tfenv (Terraform only) is the older alternative. In CI, the setup actions pin the version instead (Plan on Pull Request).
Terragrunt: less repetition across environments
The folder-per-environment layout repeats the backend block, provider block and module call in every folder. Terragrunt is a thin wrapper that generates them from a hierarchy of terragrunt.hcl files:
# live/root.hcl: shared by every folder below
remote_state {
backend = "s3"
generate = { path = "backend.tf", if_exists = "overwrite" }
config = {
bucket = "acme-tfstate-123456789012-eu-west-1"
key = "${path_relative_to_include()}/terraform.tfstate" # one key per folder, automatically
region = "eu-west-1"
encrypt = true
use_lockfile = true
}
}# live/prod/network/terragrunt.hcl
include "root" {
path = find_in_parent_folders("root.hcl")
}
terraform {
source = "git::https://github.com/acme/tf-modules.git//network?ref=v1.4.0"
}
inputs = {
name = "linkly-prod"
cidr = "10.20.0.0/16"
}$ cd live/prod && terragrunt run --all plan # every unit below, in dependency orderWorth it with many units and environments; overkill for one or two states. It works with both CLIs (terraform_binary, or TG_TF_PATH).
Atlantis and the hosted platforms
Atlantis is a self-hosted server that runs plan and apply from pull-request comments: it plans when a PR changes .tf files, posts the output, holds a per-directory lock until merge, and applies on atlantis apply. It implements the workflow of the CI lesson without writing it yourself.
# atlantis.yaml
version: 3
projects:
- name: network-prod
dir: live/prod/network
workflow: default
apply_requirements: [approved, mergeable]Hosted alternatives (often called TACOS: Terraform automation and collaboration software) add policy, drift detection, cost estimates and RBAC: HCP Terraform (Terraform only), Spacelift, env0, Scalr, Terrateam, Digger (runs inside your own CI). Most support OpenTofu.
Security and policy scanners
They read the HCL or the plan JSON and report misconfigurations: unencrypted buckets, open security groups, missing logging.
| Tool | Notes |
|---|---|
Trivy (trivy config .) |
absorbed tfsec; also scans images and SBOMs (Supply Chain Security) |
Checkov (checkov -d .) |
large built-in policy library, also scans plan JSON (-f plan.json) |
| OPA / Conftest | your own rules in Rego against show -json output: "no delete on aws_db_instance", "all buckets tagged" |
| KICS, Terrascan | further open-source scanners |
$ trivy config --severity HIGH,CRITICAL .
…
main.tf (terraform)
Tests: 12 (SUCCESSES: 10, FAILURES: 2)
Failures: 2 (HIGH: 2, CRITICAL: 0)
AWS-0107 (HIGH): Security group rule allows unrestricted ingress from any IP address.
…The plan-JSON policy in the CI lesson's ci.sh is the same idea with jq; policy engines make such rules reusable across repositories. The secrets-policy course (Secrets & Policy as Code) goes deeper.
Cost: Infracost
Infracost prices a plan before it is applied and posts the difference to the pull request:
$ infracost breakdown --path plan.json
Name Monthly Qty Unit Monthly Cost
aws_nat_gateway.this["eu-west-1a"]
├─ NAT gateway 730 hours $35.04
└─ Data processed Monthly cost depends on usage: $0.048 per GB
…(Prices in the sample are illustrative; Infracost uses current public prices.) A pull request that silently adds three NAT gateways or a db.r7g.4xlarge gets noticed before the bill does.
Documentation and hooks
- terraform-docs generates the inputs/outputs tables of a module's README from
variables.tfandoutputs.tf(terraform-docs markdown table . > README.md). - pre-commit-terraform runs
fmt,validate, tflint, terraform-docs and scanners as Git pre-commit hooks, catching problems before a push.
Other ways to write infrastructure as code
| Tool | How it differs |
|---|---|
| Pulumi | general-purpose languages (TypeScript, Python, Go, C#) instead of HCL; its own state service or self-managed backends |
| AWS CloudFormation / CDK | AWS-only, state managed by AWS (CloudFormation and CDK) |
| Crossplane | infrastructure as Kubernetes custom resources, reconciled continuously by controllers (GitOps-friendly) |
| CDK for Terraform | HashiCorp's code-first front end for Terraform; check its current support status before adopting it |
| Ansible | configuration management of servers; often used after Terraform creates them (Ansible) |
Terraform/OpenTofu stay the most common choice for multi-cloud and multi-service infrastructure because of the provider ecosystem and the plan-review workflow you practised in this course.
Test yourself
What problem does Terragrunt mainly solve?
- Provider downloads
- Repeating backend, provider and module boilerplate across many environment folders
- State encryption
- Linting
Which tool posts the cost difference of a plan to a pull request?
- tflint
- Infracost
- Atlantis
- terraform-docs
How do OPA/Conftest policies usually check Terraform changes?
- By calling the AWS API
- By evaluating Rego rules against the plan JSON from
show -json - By editing state
- By linting provider binaries