terraform
assertion_error
ai_generated
true
错误:资源前置条件失败:必须满足所有前置条件
Error: Resource precondition failed: All preconditions must be met
ID: terraform/lifecycle-precondition-failed
85%修复率
83%置信度
1证据数
2024-02-20首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.5.0 | active | — | — | — |
| 1.6.0 | active | — | — | — |
| 1.7.0 | active | — | — | — |
| 1.8.0 | active | — | — | — |
根因分析
资源配置中的生命周期前置条件块在计划或应用阶段评估为假。
English
A lifecycle precondition block in a resource configuration evaluated to false during the plan or apply phase.
官方文档
https://developer.hashicorp.com/terraform/language/meta-arguments/lifecycle#precondition-and-postcondition解决方案
-
检查前置条件表达式。例如,如果 precondition { condition = var.instance_count > 0 error_message = "实例计数必须为正" } 失败,请将 var.instance_count 设置为正值。使用 terraform console 测试条件:terraform console 然后评估 var.instance_count > 0。 -
如果前置条件依赖于数据源输出,请确保数据源配置正确并返回预期值。如果需要,向数据源添加 depends_on。
-
暂时删除或修改前置条件以允许应用继续,然后修复根本原因并重新添加前置条件。
无效尝试
常见但无效的做法:
-
Comment out the precondition block and re-apply without fixing the underlying condition.
70% 失败
The precondition exists to enforce an invariant; bypassing it may lead to incorrect infrastructure state.
-
Change the precondition condition to always true without understanding why it failed.
90% 失败
This defeats the purpose of the precondition and masks real issues.
-
Run terraform plan -refresh-only to update state before applying.
80% 失败
Preconditions are evaluated during plan; refresh-only doesn't change the logical condition causing the failure.