Terraform Advanced — Target & Surgical Applies

less than 1 minute read

Apply only the resources you need to change.


-target Flag

# Apply only a specific resource
terraform apply -target=aws_instance.app

# Apply a module
terraform apply -target=module.networking

# Multiple targets
terraform apply -target=aws_instance.app -target=aws_security_group.app

When to Use -target

✅ Emergency hotfix — need to change one resource NOW
✅ Debugging — isolate a failing resource
✅ Performance — large state, small change
❌ Regular workflow — always do full applies normally

The -replace Flag

# Force recreate a specific resource
terraform apply -replace=aws_instance.app

# This is the modern replacement for terraform taint

Destroy Single Resource

terraform destroy -target=aws_instance.temp

⚠️ Warning: -target can leave your state inconsistent if resources have dependencies. Always run a full terraform plan after targeted operations to verify.


What’s Next?

Split large states for better performance.

← Refresh Control Micro-State Pattern →

Updated: