# Error: Invalid terraform version constraint: version constraint "~> 1.0, >= 1.2" contains invalid operators or syntax

- **ID:** `terraform/invalid-terraform-version-constraint-syntax`
- **Domain:** terraform
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

The version constraint string in the required_version block has a syntax error, such as mixing incompatible operators or using unsupported characters.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Terraform v1.0 | active | — | — |
| Terraform v1.1 | active | — | — |
| Terraform v1.2 | active | — | — |

## Workarounds

1. **Use a single valid constraint: `terraform { required_version = ">= 1.2" }` or `required_version = "~> 1.2"` without combining multiple operators.** (95% success)
   ```
   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 `>=`.** (85% success)
   ```
   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.** (90% success)
   ```
   Validate the constraint syntax using `terraform version` command or an online HCL validator before applying.
   ```

## Dead Ends

- **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% fail)
- **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% fail)
- **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% fail)
