What Happens If You Manually Delete a Resource in the Cloud Console?

Manually deleting a cloud resource outside of Terraform — such as via the AWS Console, Azure Portal, or GCP Console — creates a situation called configuration drift. Understanding how Terraform handles this is critical for maintaining infrastructure integrity.

What is Configuration Drift?

Drift occurs when the real-world state of your infrastructure differs from what Terraform’s state file records. The state file still believes the resource exists, but the cloud provider no longer has it.

What Terraform Does on the Next Plan

When you run terraform plan after a manual deletion, Terraform will:

  1. Refresh the state by querying the cloud provider.
  2. Detect that the resource is gone from the provider.
  3. Propose to recreate the resource to match your configuration.
# Example terraform plan output after manual deletion

# aws_instance.web will be created
+ resource "aws_instance" "web" {
    + ami           = "ami-0c55b159cbfafe1f0"
    + instance_type = "t2.micro"
    ...
  }

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

How to Detect Drift Without Planning

# Refresh state to detect drift without making changes
terraform refresh

# Or use plan with refresh only (Terraform 1.1+)
terraform plan -refresh-only

Options After Detecting Drift

Option 1: Let Terraform recreate it — just run terraform apply and the resource comes back.

Option 2: Accept the deletion — remove it from your .tf files and run terraform state rm to remove it from state without recreating it.

# Remove from state without destroying (resource is already gone)
terraform state rm aws_instance.web

Option 3: Import it back — if you recreated it manually and want Terraform to manage the new one:

terraform import aws_instance.web i-0newinstanceid123

Best Practice: Never Modify Terraform-Managed Resources Manually

The golden rule: if Terraform manages it, all changes must go through Terraform. Manual changes bypass the plan/apply review cycle and can lead to unintended infrastructure states.

Key Takeaway

Manually deleting a resource causes drift. Terraform detects it on the next plan and proposes recreation. Use terraform plan -refresh-only regularly in production environments to catch drift before it causes problems.

(Visited 1 times, 1 visits today)