How to fix deposed object in Terraform

TerraformINTERMEDIATEHIGHUpdated Dec 30, 2025· 155 views

A deposed object occurs when Terraform's "create_before_destroy" lifecycle fails mid-operation, leaving the old resource stuck in state. This happens when resource creation succeeds but destruction fails, or operations are interrupted. Fix by running terraform apply again or manually cleaning up state.

Quick fix

Fixes deposed object

terraform apply
  1. Run terraform apply again to retry destruction
  2. Verify the resource still exists in your infrastructure
  3. Remove the deposed object from state (if external deletion succeeded)
  4. Re-import the resource if you want to manage it again
terraform — error
terraform apply
deposed object

What this error means

A "deposed object" appears in Terraform when a resource is configured with the "create_before_destroy" lifecycle option and something goes wrong during the replacement process. Normally, Terraform destroys a resource before creating its replacement. However, with "create_before_destroy = true", Terraform reverses this order: it creates the new resource first, then destroys the old one. If the destruction fails or gets interrupted, the old resource becomes "deposed" — it's marked for deletion but still exists in Terraform's state and your actual infrastructure. This mismatch between state and reality is what causes the error. Terraform thinks the resource should be gone, but it's still running. The state file holds two versions of the resource: the new current one and the old deposed one.

Typical symptoms

  • Terraform plan or apply shows '(deposed)' alongside a resource name
  • Repeated terraform apply runs seem to hang on the same resource
  • Resource exists in your cloud provider but Terraform wants to destroy it
  • Error messages mentioning 'deposed' state or failed destroy operations
  • Resource replacement operations that worked before now get stuck

Common causes

  1. Terraform apply was interrupted (Ctrl+C, network timeout, CI/CD failure) during create-before-destroy operation
  2. The destroy operation failed due to API errors, permission issues, or cloud provider problems while the new resource creation succeeded
  3. External changes or dependencies prevent the old resource from being deleted (other resources still reference it)
  4. State file corruption or manual state modifications that left inconsistent data
  5. Provider-specific issues where the resource exists in the cloud but Terraform can't destroy it

How to fix "deposed object"

1Run terraform apply again to retry destruction

The simplest fix is to let Terraform try again. Run:

bash
terraform apply

Terraform will attempt to destroy the deposed object in this run. If there were temporary API issues or network problems, this often succeeds. Monitor the output carefully to see if the deposed resource gets cleaned up.

This should be your first attempt — in many cases, transient failures resolve on retry.

2Verify the resource still exists in your infrastructure

Before removing from state, verify the old resource actually exists in your cloud provider:

- Check your AWS/GCP/Azure/etc console for the resource
- Look at resource IDs in terraform state to match them in your provider
- Run terraform show to see current state details

bash
terraform show | grep -A 5 "deposed"

This confirms whether the resource is still running or already deleted externally.

3Remove the deposed object from state (if external deletion succeeded)

If the old resource was manually deleted in your cloud provider but Terraform still thinks it exists, remove it from state:

bash
terraform state rm 'resource_type.resource_name'

For example:

bash
terraform state rm 'aws_instance.web_server'

Important: This removes BOTH the current and deposed versions from state. Only do this if the resource no longer exists in your infrastructure.

4Re-import the resource if you want to manage it again

If you removed the resource from state but the infrastructure still exists and you want Terraform to manage it again:

bash
terraform import resource_type.resource_name resource_id

For example:

bash
terraform import aws_instance.web_server i-0123456789abcdef0

Check your provider documentation for the correct import syntax for your resource type.

5Remove and recreate the resource configuration (if needed)

If the resource is too problematic, you can replace it entirely:

1. Remove the resource from state:

bash
terraform state rm 'resource_type.resource_name'

2. Manually delete the old resource in your cloud provider

3. Update your Terraform configuration with the new resource definition

4. Run terraform apply to create the new version:

bash
terraform plan
terraform apply

This is the "clean slate" approach when other methods fail.

Advanced notes

Understanding create_before_destroy lifecycle:
The "create_before_destroy = true" option is useful for zero-downtime deployments where you need the new resource live before shutting down the old one. However, this introduces complexity: if either step fails, you're left with both resources temporarily.

Preventing deposed objects:
- Avoid interrupting terraform apply operations — if interrupted, the state gets stuck
- Ensure destroy permissions are correct for your service account/IAM role
- Test create-before-destroy in a non-production environment first
- Use state backups before major operations
- Monitor CI/CD logs for timeout issues that cause interruptions

Multiple deposed objects:
If you have multiple deposed resources, you may need to clean them up individually. Run terraform plan to see all deposed instances, then address each one.

State file recovery:
Terraform creates a backup at terraform.tfstate.backup before each state modification. If you accidentally corrupt state during cleanup, you can restore from this backup (local state only, not for remote backends).

Frequently asked questions

What does "deposed object" mean?
A "deposed object" appears in Terraform when a resource is configured with the "create_before_destroy" lifecycle option and something goes wrong during the replacement process. Normally, Terraform destroys a resource before creating its replacement. However, with "create_before_destroy = true", Terraform reverses this order: it creates the new resource first, then destroys the old one.
How do I fix "deposed object"?
A deposed object occurs when Terraform's "create_before_destroy" lifecycle fails mid-operation, leaving the old resource stuck in state. This happens when resource creation succeeds but destruction fails, or operations are interrupted. Fix by running terraform apply again or manually cleaning up state.
What causes "deposed object"?
Terraform apply was interrupted (Ctrl+C, network timeout, CI/CD failure) during create-before-destroy operation The destroy operation failed due to API errors, permission issues, or cloud provider problems while the new resource creation succeeded External changes or dependencies prevent the old resource from being deleted (other resources still reference it)
Is the "deposed object" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading