terraform module_error ai_generated true

Error: Conflicting provider version constraints: multiple modules require different versions of provider X

ID: terraform/conflicting-provider-version-constraints

Also available as: JSON · Markdown · 中文
85%Fix Rate
88%Confidence
1Evidence
2023-08-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Terraform >=1.3 active
AzureRM Provider 3.x active
AWS Provider 5.x active

Root Cause

Two or more modules in the configuration specify incompatible version constraints for the same provider, causing Terraform to fail dependency resolution.

generic

中文

配置中的两个或多个模块为同一提供程序指定了不兼容的版本约束,导致 Terraform 依赖解析失败。

Official Documentation

https://developer.hashicorp.com/terraform/language/providers/requirements#version-constraints

Workarounds

  1. 90% success Align version constraints across all modules. For example, in root module set `required_providers { aws = "~> 5.0" }` and ensure all child modules use `aws = ">= 5.0, < 6.0"`.
    Align version constraints across all modules. For example, in root module set `required_providers { aws = "~> 5.0" }` and ensure all child modules use `aws = ">= 5.0, < 6.0"`.
  2. 85% success Use `terraform providers` to inspect version requirements, then update constraints to a common range, e.g., `version = "~> 5.0"` in all modules.
    Use `terraform providers` to inspect version requirements, then update constraints to a common range, e.g., `version = "~> 5.0"` in all modules.

中文步骤

  1. 在所有模块中对齐版本约束。例如,在根模块设置 `required_providers { aws = "~> 5.0" }`,并确保所有子模块使用 `aws = ">= 5.0, < 6.0"`。
  2. 使用 `terraform providers` 检查版本要求,然后将约束更新为公共范围,例如在所有模块中使用 `version = "~> 5.0"`。

Dead Ends

Common approaches that don't work:

  1. 55% fail

    Terraform may default to the latest provider version, which could be incompatible with existing state or resources.

  2. 75% fail

    The lock file is managed by Terraform and manual edits are not preserved; also risks provider corruption.