Remove an orphan from state

Forget a resource in state without deleting the real infrastructure; the object keeps running

terraform state rm 'aws_s3_bucket.legacy'

tool
terraform43 commands
tags
terraformtroubleshootingcloud

More terraform commands

  • terraform state show 'module.vpc.aws_subnet.private[0]'

    Show all attributes of one address to investigate drift or bugs

  • terraform state list | grep -i 'aws_iam'

    Filter managed addresses to see what Terraform tracks before any state surgery

  • cat > import.tf <<'EOF' import { to = aws_instance.web id = "<id>" } EOF terraform plan -generate-config-out=generated.tf

    Declarative import; -generate-config-out writes the HCL for the imported object

  • cat >> moved.tf <<'EOF' moved { from = aws_instance.web to = aws_instance.app } EOF

    Rename addresses in code without destroy and recreate; the change stays in version control

  • terraform apply -replace='aws_instance.web'

    Force one resource to be destroyed and created again; replaces the deprecated terraform taint

all 43 terraform commands