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%Fix Rate
85%Confidence
1Evidence
2023-08-15First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.5.0 | active | — | — | — |
| 1.6.0 | active | — | — | — |
| 1.7.0 | active | — | — | — |
Root Cause
Terraform variables cannot reference other variables in their default values; defaults must be literal values.
generic中文
Terraform 变量在其默认值中不能引用其他变量,默认值必须是字面值。
Official Documentation
https://developer.hashicorp.com/terraform/language/values/variablesWorkarounds
-
95% success Replace the variable reference with a literal value, or use a local value to compute the default after variable declaration.
Replace the variable reference with a literal value, or use a local value to compute the default after variable declaration.
-
90% success Define a separate variable with no default and use a locals block to set the default based on other variables.
Define a separate variable with no default and use a locals block to set the default based on other variables.
中文步骤
将变量引用替换为字面值,或使用 local 值在变量声明后计算默认值。
定义一个无默认值的单独变量,并使用 locals 块根据其他变量设置默认值。
Dead Ends
Common approaches that don't work:
-
95% fail
Adding escape characters or quotes around the interpolation does not resolve the fundamental limitation.
-
80% fail
Moving the interpolation to a locals block still fails because the variable default is evaluated before locals are available.