# 错误：无效的资源实例键：资源实例键必须是正整数或字符串

- **ID:** `terraform/resource-config-key-too-deep`
- **领域:** terraform
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 88%

## 根因

在 Terraform 期望简单整数或字符串时，使用了复杂表达式（如列表或映射）作为资源实例键。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.5.0 | active | — | — |
| 1.6.0 | active | — | — |

## 解决方案

1. ```
   将键表达式简化为单个变量或字面值。例如，如果键应为字符串，使用 'var.environment' 而不是 'var.environment[0]'。
   ```
2. ```
   重构配置，使用具有简单键的映射的 for_each，或使用 count 与列表。
   ```

## 无效尝试

- **** — Wrapping the expression in tostring() or tolist() does not change the fundamental type mismatch. (90% 失败率)
- **** — Using count.index or for_each.key in a nested resource block still fails because the key must be a literal. (85% 失败率)
