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

其他格式: JSON · Markdown 中文 · English
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.

generic

官方文档

https://developer.hashicorp.com/terraform/language/state/import

解决方案

  1. 运行 'terraform state rm <资源地址>' 从状态中移除资源而不销毁它,然后运行 'terraform apply' 同步。
  2. 如果希望销毁该资源,在验证计划显示预期销毁后直接运行 'terraform apply'。
  3. 使用 'terraform state list' 识别完整资源地址,然后运行 'terraform state rm <地址>'。

无效尝试

常见但无效的做法:

  1. 90% 失败

    The apply will execute the destroy, removing the resource permanently.

  2. 80% 失败

    Manual edits often break state file format or leave orphaned dependencies.

  3. 70% 失败

    Terraform will try to create a new resource, conflicting with the existing state entry.