terraform
config_error
ai_generated
true
错误:变量默认值中存在无效插值:此处不能使用变量
Error: Invalid interpolation in variable default: Variables may not be used here
ID: terraform/invalid-interpolation-in-variable-default
85%修复率
85%置信度
1证据数
2023-08-15首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.5.0 | active | — | — | — |
| 1.6.0 | active | — | — | — |
| 1.7.0 | active | — | — | — |
根因分析
Terraform 变量在其默认值中不能引用其他变量,默认值必须是字面值。
English
Terraform variables cannot reference other variables in their default values; defaults must be literal values.
官方文档
https://developer.hashicorp.com/terraform/language/values/variables解决方案
-
将变量引用替换为字面值,或使用 local 值在变量声明后计算默认值。
-
定义一个无默认值的单独变量,并使用 locals 块根据其他变量设置默认值。
无效尝试
常见但无效的做法:
-
95% 失败
Adding escape characters or quotes around the interpolation does not resolve the fundamental limitation.
-
80% 失败
Moving the interpolation to a locals block still fails because the variable default is evaluated before locals are available.