# 错误：无效的 Terraform 版本约束：版本约束 "~> 1.0, >= 1.2" 包含无效的操作符或语法

- **ID:** `terraform/invalid-terraform-version-constraint-syntax`
- **领域:** terraform
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

required_version 块中的版本约束字符串存在语法错误，例如混合不兼容的操作符或使用不支持的字符。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Terraform v1.0 | active | — | — |
| Terraform v1.1 | active | — | — |
| Terraform v1.2 | active | — | — |

## 解决方案

1. ```
   Use a single valid constraint: `terraform { required_version = ">= 1.2" }` or `required_version = "~> 1.2"` without combining multiple operators.
   ```
2. ```
   If combining constraints, use only compatible operators: `terraform { required_version = ">= 1.2, < 2.0" }` (both range operators) instead of mixing `~>` and `>=`.
   ```
3. ```
   Validate the constraint syntax using `terraform version` command or an online HCL validator before applying.
   ```

## 无效尝试

- **Adding a comma between constraints without checking operator compatibility (e.g., `~> 1.0, >= 1.2`)** — The comma is allowed but the combination of `~> 1.0` (pessimistic) and `>= 1.2` can conflict; Terraform may reject ambiguous combinations. (60% 失败率)
- **Using a single equals sign (e.g., `= 1.0`) instead of `~>` or `>=`** — Single equals is valid but too restrictive; it doesn't cause the syntax error but may fail to match expected versions, leading to a different error. (40% 失败率)
- **Removing all quotes around the version constraint string** — Quotes are required for string values in HCL; removing them causes a parse error before version validation. (95% 失败率)
