Terraform Module Versioning and Safe Infrastructure Changes
Pin modules, pass versions as inputs, and make every infrastructure change reviewable as a plan before it reaches state.
- Difficulty
- advanced
- Prerequisites
- Terraform installed, State backend with locking
- Tools
- Terraform, HCL
On this page
Terraform module versioning is where infrastructure teams either earn safe incremental change or learn about it the hard way during an incident. Pin provider and module versions, pass module versions in as inputs, and make every change reviewable as a plan before it touches production state.
Version modules explicitly
Unpinned module sources float to whatever the registry serves today. Pin to a released version tag and keep a changelog. When a new version ships, upgrade deliberately instead of discovering it during an apply.
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "5.0.0"
name = var.vpc_name
cidr = var.vpc_cidr
azs = var.azs
private_subnets = var.private_subnets
public_subnets = var.public_subnets
}
module "eks" {
source = "terraform-aws-modules/eks/aws"
version = var.eks_module_version
cluster_name = var.cluster_name
vpc_id = module.vpc.vpc_id
cluster_endpoint_public_access = true
cluster_endpoint_private_access = true
}
Pass module versions through inputs
Let the root module own the version decision. Downstream modules should receive versions as values so environments can upgrade on their own schedule.
module "eks" {
source = "terraform-aws-modules/eks/aws"
cluster_name = var.cluster_name
vpc_id = module.vpc.vpc_id
cluster_endpoint_public_access = true
cluster_endpoint_private_access = true
cluster_version = var.cluster_version
}
Make every change reviewable
Local applies are how small mistakes become production incidents. In CI, run init, validate, and plan with a saved plan artifact, then review before apply.
terraform init -backend=false
terraform validate
terraform plan -out=tfplan
terraform show -json tfplan > plan.json
Classify changes before upgrading
| Change class | Typical risk | Typical handling |
|---|---|---|
| Patch | Low | Upgrade in normal change window |
| Minor | Low to medium | Upgrade with plan review |
| Major | High | Upgrade with rollback plan and canary apply |
Version pinning plus reviewable plans is the unglamorous core of safe infrastructure change management. The tooling gets better; the discipline does not.
References
- Terraform module versioning documentation — Version constraints and registry semantics.
- Terraform state locking documentation — State locking and team workflows.