0
0
Terraformcloud~5 mins

Terraform apply -replace flag - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the -replace flag do in terraform apply?
The -replace flag forces Terraform to destroy and recreate a specific resource during the apply process.
Click to reveal answer
beginner
How do you specify a resource to replace using the -replace flag?
You specify the resource address, like -replace=aws_instance.example, to tell Terraform which resource to recreate.
Click to reveal answer
intermediate
Why would you use the -replace flag instead of manually deleting a resource?
Using -replace lets Terraform handle the destruction and recreation safely, keeping the state consistent and avoiding manual errors.
Click to reveal answer
intermediate
Can you replace multiple resources in one terraform apply command?
Yes, you can use multiple -replace flags to replace several resources at once.
Click to reveal answer
advanced
What happens if you use -replace on a resource that does not exist in the state?
Terraform will show an error because it cannot replace a resource that is not tracked in the state.
Click to reveal answer
What is the main purpose of the -replace flag in terraform apply?
ATo force recreation of a resource
BTo skip a resource during apply
CTo update Terraform version
DTo backup the state file
How do you specify which resource to replace?
ABy resource ID in the cloud provider
BBy resource tag
CBy resource name in the configuration file
DBy resource address in Terraform state
Can you replace multiple resources in one command?
AYes, by using multiple <code>-replace</code> flags
BYes, by listing resources separated by commas
CNo, only one resource at a time
DNo, you must run separate apply commands
What happens if you try to replace a resource not in the state?
ATerraform creates a new resource
BTerraform shows an error
CTerraform ignores it
DTerraform deletes all resources
Why is using -replace safer than manually deleting a resource?
AIt updates the provider automatically
BIt backs up the resource
CIt keeps Terraform state consistent
DIt speeds up apply time
Explain how the -replace flag works in terraform apply and when you might use it.
Think about how Terraform manages resources and state.
You got /4 concepts.
    Describe the steps Terraform takes when you run terraform apply -replace=resource.address.
    Focus on the lifecycle of the resource during apply.
    You got /4 concepts.