Terraform "removed" Block Errors - Resource Still Declared in CI
A removed {} block (Terraform 1.7+) drops a resource from state without destroying the real object. It errors when the resource is still declared in config, or when the target address is wrong.
What this error means
plan fails on a removed block because the named resource is still present in the configuration, or the from address does not match anything Terraform tracks. The state removal does not proceed.
Error: Removed resource still exists
on removed.tf line 1:
1: removed {
This statement declares a removal of aws_instance.legacy, but this resource
block is still present in the configuration. To remove a resource, its
configuration must be deleted.Common causes
Resource block still in config
A removed block requires the resource block to be deleted from config. Keeping the block while adding removed is contradictory and rejected.
Wrong removed target address
The from address must match a resource Terraform currently tracks. A typo or wrong index makes the removal target nothing.
How to fix it
Delete the resource block, then declare the removal
Remove the resource block from config and add a removed block that forgets it without destroying the object.
# (the resource "aws_instance" "legacy" block is deleted)
removed {
from = aws_instance.legacy
lifecycle {
destroy = false # forget from state, keep the real resource
}
}Correct the target address
- Confirm the
fromaddress matches whatterraform state listshows. - Ensure the corresponding
resourceblock has been deleted from config. - Run
terraform planto confirm the removal (not a destroy) is planned.
How to prevent it
- Delete the
resourceblock in the same change that adds aremovedblock. - Match the
fromaddress toterraform state listoutput. - Use
lifecycle { destroy = false }when you intend to keep the real object.