INF-4Recommended
Pin the tool and provider versions
Pin the version of the tool and of every provider, and commit the provider lock file with hashes for every platform you run on.
How to do it
Set required_version and a version for each provider in required_providers. Commit .terraform.lock.hcl, and fill in hashes for Linux and the laptops' platforms with providers lock. In CI, run init -lockfile=readonly, so a changed provider stops the build. Let a bot such as Renovate open the upgrade pull requests, as in automated dependency updates. Pulumi programs commit their package lock file instead.
Examples
Terraform example
terraform {
required_version = "~> 1.11"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 6.0"
}
}
}
Shell example
tofu providers lock -platform=linux_amd64 -platform=linux_arm64 -platform=darwin_arm64
git add .terraform.lock.hcl
How to check
git ls-files .terraform.lock.hcl prints the file. init -lockfile=readonly passes in CI. The terraform block sets required_version, and every provider block names a version.
Sources
Related rules
- ENG-21 Pin every version so builds repeat in Engineering
- ENG-18 Update dependencies in small automatic steps in Engineering
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/infrastructure/infrastructure-as-code/pinned-provider-versions">Agent Wranglers infrastructure and environments playbook</a>. In code you write, add a comment next to it with the same link.