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%修复率
87%置信度
1证据数
2023-12-01首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| Terraform v1.5.0 | active | — | — | — |
| Terraform v1.6.0 | active | — | — | — |
| Terraform v1.7.0 | active | — | — | — |
根因分析
定义为列表类型约束的变量被提供了单个字符串值而不是列表。
English
A variable defined with a list type constraint was provided with a single string value instead of a list.
官方文档
https://developer.hashicorp.com/terraform/language/values/variables#type-constraints解决方案
-
在 .tfvars 文件中,使用列表语法:'variable_name = ["value1", "value2"]'。
-
对于环境变量,使用 JSON 编码:'export TF_VAR_variable_name='["value1","value2"]''。
-
如果使用 -var 标志:'terraform apply -var='variable_name=["value"]''。
无效尝试
常见但无效的做法:
-
90% 失败
The single string does not satisfy the list(type = list(string)) constraint.
-
80% 失败
Environment variables are always interpreted as strings, not lists.
-
70% 失败
Other parts of the configuration likely use for_each or other list-specific functions.