How to fix Error: Removed block with invalid resource address in Terraform
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.
Quick fix
Fixes Error: Removed block with invalid resource address
# Wrong
removed {
from = aws_instance.example[0]
}
# Correct
removed {
from = aws_instance.example
}- Remove instance keys from the resource address
- Use bare resource addresses without quotes
- Verify you are not trying to remove a data source
- For module resources, use the correct path syntax
# Wrongremoved {from = aws_instance.example[0]}# Correctremoved {from = aws_instance.example}Error: Removed block with invalid resource address
What this error means
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.
Typical symptoms
- Terraform plan or apply fails with "Error: Removed block with invalid resource address"
- You added a removed block but the address format does not match Terraform expectations
- The error occurs even though the resource exists in your state
- Trying to remove a specific resource instance (with index) fails with this error
Common causes
- Using instance keys in the from argument (e.g., from = aws_instance.example[0]) - removed blocks do not support index notation
- Using data source addresses (from = data.aws_instance.example) - data sources cannot be removed via removed blocks
- Using quoted strings around the address (from = "aws_instance.example") instead of bare references
- Module instance keys in the from argument (e.g., from = module.example[0]) - removed blocks do not support module instance keys
- Incorrect module path syntax or missing intermediate resources in the address
How to fix "Error: Removed block with invalid resource address"
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.
Advanced notes
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.
Frequently asked questions
- What does "Error: Removed block with invalid resource address" mean?
- 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.
- How do I fix "Error: Removed block with invalid resource address"?
- 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.
- What causes "Error: Removed block with invalid resource address"?
- Using instance keys in the from argument (e.g., from = aws_instance.example[0]) - removed blocks do not support index notation Using data source addresses (from = data.aws_instance.example) - data sources cannot be removed via removed blocks Using quoted strings around the address (from = "aws_instance.example") instead of bare references
- Is the "Error: Removed block with invalid resource address" error serious?
- It is a medium-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐Terraform Official Documentation
- ๐
- ๐
- ๐
- ๐