Introduction Terraform module version errors occur when the specified version cannot be found in the Terraform Registry, a Git repository, or a local path. This blocks terraform init and prevents infrastructure deployment.
Symptoms - `terraform init` returns: "Module version x.y.z not found" - Error: "Could not download module" - Error: "Module source has changed" - Module registry returns 404 for the version - Private module registry not accessible
Common Causes - Module version does not exist (typo in version number) - Git tag not pushed or tag name does not match version constraint - Private registry authentication failed - Module source URL changed or repository moved - Version constraint too restrictive (e.g., = "1.2.3" when only 1.2.4 exists)
Step-by-Step Fix 1. **Check module source and version**: ```bash cat .terraform/modules/modules.json grep -A5 "module." *.tf ```
- 1.Verify module version exists in registry:
- 2.```bash
- 3.curl -s https://registry.terraform.io/v1/modules/hashicorp/consul/aws/versions | jq '.modules[0].versions[].version'
- 4.
` - 5.For Git modules, check tags exist:
- 6.```bash
- 7.git ls-remote --tags https://github.com/org/terraform-module.git
- 8.# Verify the tag matches your version constraint
- 9.
` - 10.Update version constraint:
- 11.```hcl
- 12.# Too restrictive
- 13.module "vpc" {
- 14.source = "terraform-aws-modules/vpc/aws"
- 15.version = "3.14.0" # This version may not exist
# Better module "vpc" { source = "terraform-aws-modules/vpc/aws" version = "~> 3.14" } ```