What if you could fix just one broken cloud resource instantly without touching the rest?
Why Terraform apply -replace flag? - Purpose & Use Cases
Imagine you have a cloud setup with many resources like servers and databases. One resource is acting up, but you don't want to touch the others. You try to fix it by manually deleting and recreating it through the cloud console or command line.
This manual way is slow and risky. You might delete the wrong resource or forget to update dependencies. It's easy to make mistakes, and fixing them can cause downtime or extra costs.
The terraform apply -replace flag lets you tell Terraform to destroy and recreate just the specific resource you want. It does this safely and automatically, keeping the rest of your setup untouched and consistent.
Delete resource manually in cloud console
terraform applyterraform apply -replace=resource.type.name
This flag makes targeted fixes simple and safe, so you can quickly refresh a resource without risking your whole infrastructure.
Your database instance has a configuration error. Instead of rebuilding the entire environment, you run terraform apply -replace=aws_db_instance.mydb to recreate just that database cleanly.
Manual fixes are slow and error-prone.
-replace targets specific resources for safe recreation.
It saves time and reduces risk in managing cloud infrastructure.