The Terraform removed block requires a properly formatted resource address in the `from` argument. Common mistakes include using instance keys (like [0]), data sources, or quoted strings instead of bare resource references.
The removed block in Terraform (v1.7+) is used to safely remove resources from state without destroying the actual infrastructure. The `from` argument must reference a valid resource address in a specific format. Terraform validates this address when you run plan or apply, and rejects invalid syntax with this error.
The from argument in a removed block must NOT include instance indices. Remove any [0], ["key"], or similar notation.
# Wrong
removed {
from = aws_instance.example[0]
}
# Correct
removed {
from = aws_instance.example
}If you need to remove a specific instance, use the terraform state rm command instead.
The resource address must be an unquoted reference. Do not wrap it in strings.
# Wrong
removed {
from = "aws_instance.example"
}
# Correct
removed {
from = aws_instance.example
}Data sources cannot be removed via removed blocks. To stop managing a data source, simply delete the data source block from your configuration.
# This is invalid - data sources are not allowed in removed blocks
removed {
from = data.aws_availability_zones.available
}
# Instead, just delete the data block from your configurationIf removing a resource from within a module, include the module path without instance keys:
# Correct for module resources
removed {
from = module.my_module.aws_instance.example
}
# Wrong - instance key on module
removed {
from = module.my_module[0].aws_instance.example
}Every removed block must include a lifecycle block to control destruction behavior:
removed {
from = aws_instance.example
lifecycle {
destroy = false # Keep infrastructure running
}
}Set destroy = false to remove from state without destroying infrastructure, or destroy = true to actually destroy the resource.
If you need to remove a specific instance (with count or for_each), use the CLI command instead of a removed block:
# Remove a count-indexed instance
terraform state rm 'aws_instance.example[0]'
# Remove a for_each instance
terraform state rm 'aws_instance.example["key"]'After running this command, you can safely delete the resource from your configuration.
The removed block is a declarative way to manage state cleanup introduced in Terraform 1.7. Unlike the older terraform state rm command approach, removed blocks are version-controlled and part of your configuration. However, they have stricter limitations: they cannot use instance keys for count or for_each, cannot remove data sources, and cannot remove module instances with keys. For complex refactoring scenarios involving nested modules or dynamic resource indices, you may need to combine removed blocks with manual terraform state rm commands or use moved blocks for renaming scenarios.
Error: Error rendering template: template not found
How to fix "template not found" error in Terraform
Error: Error generating private key
How to fix 'Error generating private key' in Terraform
Error creating Kubernetes Service: field is immutable
How to fix "field is immutable" errors in Terraform
Error: Error creating local file: open: permission denied
How to fix "Error creating local file: permission denied" in Terraform
Error: line endings have changed from CRLF to LF
Line endings have changed from CRLF to LF in Terraform