terraform
config_error
ai_generated
true
错误:无效索引:输出值为列表但未指定索引
Error: Invalid index: output value is a list but no index was specified
ID: terraform/invalid-index-in-output
88%修复率
85%置信度
1证据数
2023-09-15首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| Terraform >=1.0 | active | — | — | — |
| AWS Provider 5.x | active | — | — | — |
根因分析
模块输出返回列表,但在引用时未指定索引,导致 Terraform 期望单个值时类型不匹配。
English
A module output that returns a list is referenced without an index, causing a type mismatch when Terraform expects a single value.
官方文档
https://developer.hashicorp.com/terraform/language/expressions/references#outputs解决方案
-
使用显式索引引用输出,例如 `module.my_module.output_name[0]` 或使用 `element(module.my_module.output_name, 0)`。
-
如果需要所有值,使用 `module.my_module.output_name[*]` 以保留列表类型。
无效尝试
常见但无效的做法:
-
60% 失败
Outputs do not support count; this fix leads to a syntax error.
-
70% 失败
Alters the module's contract and may cause downstream errors.