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. 1.Verify module version exists in registry:
  2. 2.```bash
  3. 3.curl -s https://registry.terraform.io/v1/modules/hashicorp/consul/aws/versions | jq '.modules[0].versions[].version'
  4. 4.`
  5. 5.For Git modules, check tags exist:
  6. 6.```bash
  7. 7.git ls-remote --tags https://github.com/org/terraform-module.git
  8. 8.# Verify the tag matches your version constraint
  9. 9.`
  10. 10.Update version constraint:
  11. 11.```hcl
  12. 12.# Too restrictive
  13. 13.module "vpc" {
  14. 14.source = "terraform-aws-modules/vpc/aws"
  15. 15.version = "3.14.0" # This version may not exist

# Better module "vpc" { source = "terraform-aws-modules/vpc/aws" version = "~> 3.14" } ```

Prevention - Use version constraints with ranges (~> for patch updates) - Keep .terraform.lock.hcl in version control - Test module version updates in development first - Use private module registry with proper authentication - Pin Git modules to specific commit SHAs for reproducibility