# 错误：资源实例已从配置中移除，但仍在状态文件中跟踪

- **ID:** `terraform/resource-in-config-no-longer-exists`
- **领域:** terraform
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

从 .tf 配置文件中移除了某个资源，但 Terraform 状态中仍存在该资源记录，导致计划意外地要销毁它。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Terraform v1.5.0 | active | — | — |
| Terraform v1.6.0 | active | — | — |
| Terraform v1.7.0 | active | — | — |

## 解决方案

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

## 无效尝试

- **** — The apply will execute the destroy, removing the resource permanently. (90% 失败率)
- **** — Manual edits often break state file format or leave orphaned dependencies. (80% 失败率)
- **** — Terraform will try to create a new resource, conflicting with the existing state entry. (70% 失败率)
