terraform
config_error
ai_generated
true
错误:资源实例已从配置中移除,但仍在状态文件中跟踪
Error: Resource instance has been removed from the configuration but is still tracked in the state
ID: terraform/resource-in-config-no-longer-exists
80%修复率
85%置信度
1证据数
2023-11-15首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| Terraform v1.5.0 | active | — | — | — |
| Terraform v1.6.0 | active | — | — | — |
| Terraform v1.7.0 | active | — | — | — |
根因分析
从 .tf 配置文件中移除了某个资源,但 Terraform 状态中仍存在该资源记录,导致计划意外地要销毁它。
English
A resource was removed from the .tf configuration file but Terraform still has it in the state, causing a plan to destroy it unexpectedly.
官方文档
https://developer.hashicorp.com/terraform/language/state/import解决方案
-
运行 'terraform state rm <资源地址>' 从状态中移除资源而不销毁它,然后运行 'terraform apply' 同步。
-
如果希望销毁该资源,在验证计划显示预期销毁后直接运行 'terraform apply'。
-
使用 'terraform state list' 识别完整资源地址,然后运行 'terraform state rm <地址>'。
无效尝试
常见但无效的做法:
-
90% 失败
The apply will execute the destroy, removing the resource permanently.
-
80% 失败
Manual edits often break state file format or leave orphaned dependencies.
-
70% 失败
Terraform will try to create a new resource, conflicting with the existing state entry.