terraform
config_error
ai_generated
true
错误:无效模板文件路径:给定路径无法解析为文件
Error: Invalid template file path: the given path does not resolve to a file
ID: terraform/invalid-template-file-path
92%修复率
87%置信度
1证据数
2023-10-05首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| Terraform >=0.12 | active | — | — | — |
| All providers | active | — | — | — |
根因分析
`templatefile` 函数或 `file` 函数引用的路径相对于 Terraform 根模块不存在或路径不正确。
English
The `templatefile` function or `file` function references a path that does not exist relative to the Terraform root module or the path is incorrect.
官方文档
https://developer.hashicorp.com/terraform/language/functions/templatefile解决方案
-
使用相对于模块根目录的路径:`templatefile("${path.module}/templates/config.tftpl", {})`。确保文件存在于该位置。 -
在使用前使用 `fileexists()` 检查路径:`fileexists("${path.module}/templates/config.tftpl") ? templatefile(...) : ""`。
无效尝试
常见但无效的做法:
-
70% 失败
Terraform resolves paths relative to the module directory; absolute paths often fail or break in different environments.
-
60% 失败
The path is case-sensitive and must match exactly; missing subdirectory causes resolution failure.