terraform config_error ai_generated true

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

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

Also available as: JSON · Markdown · 中文
90%Fix Rate
88%Confidence
1Evidence
2024-08-20First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Terraform v1.5.0 active
Terraform v1.6.0 active
Terraform v1.7.0 active

Root Cause

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

generic

中文

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

Official Documentation

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

Workarounds

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

中文步骤

  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'

Dead Ends

Common approaches that don't work:

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

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

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

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

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

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