# 错误：无效模板文件路径：给定路径无法解析为文件

- **ID:** `terraform/invalid-template-file-path`
- **领域:** terraform
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 92%

## 根因

`templatefile` 函数或 `file` 函数引用的路径相对于 Terraform 根模块不存在或路径不正确。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Terraform >=0.12 | active | — | — |
| All providers | active | — | — |

## 解决方案

1. ```
   使用相对于模块根目录的路径：`templatefile("${path.module}/templates/config.tftpl", {})`。确保文件存在于该位置。
   ```
2. ```
   在使用前使用 `fileexists()` 检查路径：`fileexists("${path.module}/templates/config.tftpl") ? templatefile(...) : ""`。
   ```

## 无效尝试

- **** — Terraform resolves paths relative to the module directory; absolute paths often fail or break in different environments. (70% 失败率)
- **** — The path is case-sensitive and must match exactly; missing subdirectory causes resolution failure. (60% 失败率)
