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
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.
官方文档
https://developer.hashicorp.com/terraform/language/providers/requirements解决方案
-
Use a single constraint without commas: `version = "~> 3.0"` or use multiple constraints with newlines: `version = [">= 3.0", "< 4.0"]`
-
Correct the syntax to use a list: `version = [">= 3.0", "< 4.0"]` and run 'terraform init'
无效尝试
常见但无效的做法:
-
Remove the version constraint entirely and run terraform init
60% 失败
Without constraints, Terraform may install a newer incompatible provider version.
-
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.
-
Wrap the constraint in double quotes inside the block
50% 失败
The error is about the constraint string syntax, not quoting.