Terraform modules are pinned
terraform/modules-pinned@v1
Every module a Terraform root takes from a registry or a git URL names the version it takes, so the same commit resolves to the same module twice.
| Id | terraform/modules-pinned |
| Version | v1 |
| Category | terraform |
| Default severity | error |
| Interpreter | python3 |
| Timeout | 30 seconds |
| Violations tolerated | 0 |
| Collects | terraform |
Collectors
This guardrail gathers nothing itself. It depends on the collectors below, which the CLI runs once per build before any check, and reads what they found out of GUARDRAIL_FACTS. A collector that collects nothing skips this guardrail rather than failing it.
| Collector | Gathers | Inputs it is given |
|---|---|---|
terraform | The Terraform configuration in the checkout: every root directory holding .tf files, the backend it stores state in, the providers and modules it takes on and how tightly they are pinned, the resources it declares, the variables it takes, the lock file that resolves it, and any state file left in the tree. Read out of the files themselves, so it works on a runner with no Terraform installed, and enriched with the versions an initialised root has already resolved when the terraform CLI is there. | none |
The inputs above are this guardrail's own, passed straight through. Configuring one in buildnote.json changes what is collected, and two guardrails configured the same way share the one collection.
Configuration
{
"guardrails": {
"failOn": "error",
"comment": true,
"checks": [
{
"use": "terraform/modules-pinned@v1",
"severity": "error",
"with": {
"allowMovableRefs": "false"
},
"exemptions": []
}
]
}
}Inputs
| Input | Description | Default | Environment variable |
|---|---|---|---|
allowMovableRefs | Whether a git source pinned to a tag or a branch rather than to a commit sha counts as pinned. false requires a 40 character sha, which is the only ref nobody can move. | false | GUARDRAIL_INPUT_ALLOWMOVABLEREFS |
How to fix
Pin the modules named in the violations. A registry source pins with version:
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "5.8.1"
}A git source pins with a ref in the URL, and a tag is not enough because a tag moves:
module "vpc" {
source = "git::https://github.com/acme/terraform-vpc.git?ref=6f3a1c2d9b8e4f7a0c5d2e1b3a4f5c6d7e8f9a0b"
}An unpinned module means the plan you reviewed and the plan that applied can be built from different code. A module in this repository, taken with a relative source, is already pinned by the commit and is not judged.
More in terraform
terraform/no-plaintext-secrets. Every Terraform variable named like a credential declaressensitive = true.terraform/providers-pinned. Every provider a live Terraform root requires is pinned to one exact version, and the lock file that resolves them is committed.terraform/remote-state. Every live Terraform root stores its state in a remote backend, and no state file is left in the checkout.terraform/state-encrypted. Every live Terraform root declares its backend encrypted, so the state it writes is not readable from the bucket it sits in.terraform/state-locking. Every live Terraform root declares state locking, so two applies cannot write the same state at once.