You manage Google Cloud infrastructure with Terraform, storing the state file in a Cloud Storage bucket configured as the backend. A teammate accidentally deleted a Cloud Storage bucket that is still declared in your Terraform configuration. You must restore the bucket and keep the state file accurate while minimizing manual work. What should you do next?
Delete the remote state file in Cloud Storage and run "terraform init" so Terraform can re-import existing resources.
Delete the bucket resource block from the configuration, run "terraform apply" to remove it from state, then add the block back and apply again.
Use gsutil to recreate the bucket manually, then run "terraform refresh" to sync the state file.
Run "terraform apply" in the working directory, review the plan, and confirm the action so Terraform recreates the missing bucket and updates state.
Running "terraform apply" after reviewing the proposed execution plan is the safest and simplest way to recover from resource drift that occurred outside of Terraform. During the planning phase Terraform compares the desired configuration with both the state file and the actual resources in Google Cloud. Because the bucket is missing but still tracked in state, Terraform marks it for creation and, upon confirmation, recreates it and updates the state file automatically.
Creating the bucket manually and then running "terraform refresh" breaks the declarative workflow and risks configuration drift. Removing the resource from the code and cycling it back in requires two separate applies and offers no benefit. Deleting the remote state file is dangerous; it discards Terraform's source of truth and does not recover the bucket.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is Terraform's state file used for?
Open an interactive chat with Bash
Why is running 'terraform apply' better in this scenario?
Open an interactive chat with Bash
What risks are associated with manually recreating resources outside of Terraform?
Open an interactive chat with Bash
What is resource drift in Terraform?
Open an interactive chat with Bash
How does the Terraform execution plan work?
Open an interactive chat with Bash
Why is the Terraform state file important?
Open an interactive chat with Bash
GCP Associate Cloud Engineer
Planning and implementing a cloud solution
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
Pass with Confidence.
IT & Cybersecurity Package
You have hit the limits of our free tier, become a Premium Member today for unlimited access.
Military, Healthcare worker, Gov. employee or Teacher? See if you qualify for a Community Discount.
Monthly
$19.99 $11.99
$11.99/mo
Billed monthly, Cancel any time.
$19.99 after promotion ends
3 Month Pass
$44.99 $26.99
$8.99/mo
One time purchase of $26.99, Does not auto-renew.
$44.99 after promotion ends
Save $18!
MOST POPULAR
Annual Pass
$119.99 $71.99
$5.99/mo
One time purchase of $71.99, Does not auto-renew.
$119.99 after promotion ends
Save $48!
BEST DEAL
Lifetime Pass
$189.99 $113.99
One time purchase, Good for life.
Save $76!
What You Get
All IT & Cybersecurity Package plans include the following perks and exams .