terraform config_error ai_generated true

错误:无效的 required_providers 版本约束:"~> 3.0, < 4.0" 不是有效的版本约束字符串

Error: Invalid required_providers version constraint: "~> 3.0, < 4.0" is not a valid version constraint string

ID: terraform/invalid-required-providers-version-constraint

其他格式: JSON · Markdown 中文 · English
90%修复率
88%置信度
1证据数
2024-08-20首次发现

版本兼容性

版本状态引入弃用备注
Terraform v1.5.0 active
Terraform v1.6.0 active
Terraform v1.7.0 active

根因分析

required_providers 中的版本约束语法格式错误或使用了不支持的运算符。

English

The version constraint syntax in required_providers is malformed or uses unsupported operators.

generic

官方文档

https://developer.hashicorp.com/terraform/language/providers/requirements

解决方案

  1. Use a single constraint without commas: `version = "~> 3.0"` or use multiple constraints with newlines: `version = [">= 3.0", "< 4.0"]`
  2. Correct the syntax to use a list: `version = [">= 3.0", "< 4.0"]` and run 'terraform init'

无效尝试

常见但无效的做法:

  1. Remove the version constraint entirely and run terraform init 60% 失败

    Without constraints, Terraform may install a newer incompatible provider version.

  2. Use a comma instead of spaces between constraints: "~> 3.0,< 4.0" 90% 失败

    The comma is still invalid; Terraform requires spaces or newlines between constraints.

  3. Wrap the constraint in double quotes inside the block 50% 失败

    The error is about the constraint string syntax, not quoting.