Removed blocks

Removed blocks

A removed block removes a resource from Terraform’s state without destroying the real object. Terraform stops managing it, but the infrastructure keeps running — the opposite of deleting the resource block, which makes Terraform destroy the object.

  flowchart LR
    delete["Delete resource block"] --> destroyed["Object <b>destroyed</b>"]
    removed["Delete resource block<br/>+ removed block"] --> forgotten["Object <b>kept</b>,<br/>removed from state"]

Delete the resource block and add a removed block in its place. The from argument is the address the resource had, and destroy = false tells Terraform to forget the object rather than destroy it:

main.tf
1
2
3
4
5
6
7
removed {
  from = aws_s3_bucket.assets

  lifecycle {
    destroy = false
  }
}

The plan confirms the object will be forgotten, not destroyed:

 # aws_s3_bucket.assets will no longer be managed by Terraform,
 # but will not be destroyed

Plan: 0 to add, 0 to change, 0 to destroy.

Note that from takes an address without instance keys — aws_s3_bucket.assets, not aws_s3_bucket.assets[0] — and applies to all instances of the resource. Whole modules can be removed the same way:

main.tf
1
2
3
4
5
6
7
removed {
  from = module.legacy_network

  lifecycle {
    destroy = false
  }
}
After the removed block is applied, the object is unmanaged: future terraform apply runs will not update or protect it. Make sure something (or someone) else takes over ownership.

Typical use cases are handing a resource over to another team or Terraform configuration (often paired with an import block on the receiving side), or keeping a resource that was created as an experiment.

Best practices

  • Use a removed block instead of terraform state rm — it is declarative, previewable in terraform plan, and reviewable in version control.
  • Double-check the plan says the object “will not be destroyed” before applying.
  • Pair a removed block in one configuration with an import block in another to move a resource between configurations without downtime.
  • Remove the block from your configuration after it has been applied.