terraform
type_error
ai_generated
true
Error: Invalid value for variable: value must be a list of strings, got a string
ID: terraform/variable-type-constraint-violation
90%Fix Rate
87%Confidence
1Evidence
2023-12-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| Terraform v1.5.0 | active | — | — | — |
| Terraform v1.6.0 | active | — | — | — |
| Terraform v1.7.0 | active | — | — | — |
Root Cause
A variable defined with a list type constraint was provided with a single string value instead of a list.
generic中文
定义为列表类型约束的变量被提供了单个字符串值而不是列表。
Official Documentation
https://developer.hashicorp.com/terraform/language/values/variables#type-constraintsWorkarounds
-
95% success In .tfvars file, use list syntax: 'variable_name = ["value1", "value2"]'.
In .tfvars file, use list syntax: 'variable_name = ["value1", "value2"]'.
-
90% success For environment variables, use JSON encoding: 'export TF_VAR_variable_name='["value1","value2"]''.
For environment variables, use JSON encoding: 'export TF_VAR_variable_name='["value1","value2"]''.
-
85% success If using -var flag: 'terraform apply -var='variable_name=["value"]''.
If using -var flag: 'terraform apply -var='variable_name=["value"]''.
中文步骤
在 .tfvars 文件中,使用列表语法:'variable_name = ["value1", "value2"]'。
对于环境变量,使用 JSON 编码:'export TF_VAR_variable_name='["value1","value2"]''。
如果使用 -var 标志:'terraform apply -var='variable_name=["value"]''。
Dead Ends
Common approaches that don't work:
-
90% fail
The single string does not satisfy the list(type = list(string)) constraint.
-
80% fail
Environment variables are always interpreted as strings, not lists.
-
70% fail
Other parts of the configuration likely use for_each or other list-specific functions.