# 错误：变量值无效：值必须是字符串列表，但得到的是字符串

- **ID:** `terraform/variable-type-constraint-violation`
- **领域:** terraform
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

定义为列表类型约束的变量被提供了单个字符串值而不是列表。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Terraform v1.5.0 | active | — | — |
| Terraform v1.6.0 | active | — | — |
| Terraform v1.7.0 | active | — | — |

## 解决方案

1. ```
   在 .tfvars 文件中，使用列表语法：'variable_name = ["value1", "value2"]'。
   ```
2. ```
   对于环境变量，使用 JSON 编码：'export TF_VAR_variable_name='["value1","value2"]''。
   ```
3. ```
   如果使用 -var 标志：'terraform apply -var='variable_name=["value"]''。
   ```

## 无效尝试

- **** — The single string does not satisfy the list(type = list(string)) constraint. (90% 失败率)
- **** — Environment variables are always interpreted as strings, not lists. (80% 失败率)
- **** — Other parts of the configuration likely use for_each or other list-specific functions. (70% 失败率)
