terraform config_error ai_generated true

Error: Conflicting version constraints for module 'vpc': required_version = ">= 1.6, < 2.0" but other module requires ">= 1.5, < 1.8"

ID: terraform/conflicting-terraform-version-constraints

Also available as: JSON · Markdown · 中文
80%Fix Rate
85%Confidence
1Evidence
2023-09-15First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Terraform v1.5 active
Terraform v1.6 active
Terraform v1.7 active

Root Cause

Multiple modules define overlapping but conflicting required_version constraints, making it impossible to select a single Terraform version that satisfies all.

generic

中文

多个模块定义了重叠但冲突的 required_version 约束,导致无法选择满足所有要求的单一 Terraform 版本。

Official Documentation

https://developer.hashicorp.com/terraform/language/expressions/version-constraints

Workarounds

  1. 85% success Align all module required_version constraints to a single compatible range. For example, change all to required_version = ">= 1.6, < 2.0". Then run 'terraform init -upgrade' to reinitialize.
    Align all module required_version constraints to a single compatible range. For example, change all to required_version = ">= 1.6, < 2.0". Then run 'terraform init -upgrade' to reinitialize.
  2. 75% success If alignment is not possible, remove required_version from conflicting modules and rely on root module's constraint. Edit each module's versions.tf to delete the required_version line, then run 'terraform init'.
    If alignment is not possible, remove required_version from conflicting modules and rely on root module's constraint. Edit each module's versions.tf to delete the required_version line, then run 'terraform init'.

中文步骤

  1. Align all module required_version constraints to a single compatible range. For example, change all to required_version = ">= 1.6, < 2.0". Then run 'terraform init -upgrade' to reinitialize.
  2. If alignment is not possible, remove required_version from conflicting modules and rely on root module's constraint. Edit each module's versions.tf to delete the required_version line, then run 'terraform init'.

Dead Ends

Common approaches that don't work:

  1. 95% fail

    Root module constraints are combined with child module constraints; overriding doesn't work because Terraform enforces intersection of all constraints.

  2. 70% fail

    Removing constraints from child modules may cause them to be used with incompatible Terraform versions, leading to other errors. Terraform still validates root constraints.

  3. 85% fail

    This doesn't resolve existing conflicts; it may introduce new ones if modules have different minimum version requirements.