rmdir.cn

terraform state rm

从状态中移除资源

语法

terraform state rm <资源地址> [选项]

说明

将资源从 Terraform 状态文件中移除,但不会销毁实际的云资源。移除后 Terraform 不再管理该资源。 常见场景:接管已有资源、拆分项目、废弃部分配置但保留资源。使用时需谨慎,确保资源确实不再需要 Terraform 管理。

参数

  • -dry-run

    仅显示将要移除的资源,不实际移除

  • -state

    指定状态文件路径

示例

移除单个资源

从状态中移除一个资源(不删除实际资源)

terraform state rm aws_instance.deprecated

模拟移除

先查看将移除哪些资源

terraform state rm -dry-run module.old