# 错误：无效的动态块迭代器：动态块的迭代器必须是单个单词，不能是复杂表达式

- **ID:** `terraform/dynamic-block-iterator-invalid`
- **领域:** terraform
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

动态块的 iterator 参数被设置为复杂表达式（如函数调用或属性引用），而不是简单的变量名。

## 版本兼容性

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

## 解决方案

1. ```
   使用一个简单的、单词的标识符作为迭代器，且该标识符在当前作用域中未被使用。例如，如果遍历标签列表，使用 'tag' 作为迭代器。
   ```
2. ```
   如果有嵌套的动态块，为每一层使用不同的迭代器名称，例如 'outer' 和 'inner'。
   ```

## 无效尝试

- **** — The iterator must be a new variable name, not an existing expression. Terraform uses it to create a temporary variable within the block. (90% 失败率)
- **** — The default iterator 'each' works only if not already used by another dynamic block in the same resource. If 'each' is used elsewhere, it causes conflicts. (60% 失败率)
- **** — The iterator must be an unquoted identifier, not a string. Quoting makes it a string literal, which is not a valid variable name. (95% 失败率)
