Remote state file accidental deletion

Hi everyone, first post!
We have been using TF and TF cloud for over a year now, TF cloud stores our remote state files. Recently, one of our team member accidentally deleted a remote state file, meaning, the contents of the remote workspace are empty. No one can run the workspace, the error is: Luckily, I still have the .terraform local state file on my machine.

Betting this has happened before to someone, can you kindly advise how I can go about replacing this. I also do not want terraform to destroy anything running in AWs that is using the workspace, if that is possible.

Peter

Im wondering if this wold work:
terraform state rm aws_backup_vault.awsbackup

After this command succeeds, the state associated with the current configuration will no longer be aware of the steve-backup_vault object. Since you’ve removed the resource "aws_backup_vault" "awsbackup" block from the configuration, a subsequent terraform apply should say nothing about it, because it now exists neither in the configuration nor in the state.
If that object will now be managed by some other Terraform configuration then you can import it to bind it to a resource in that other configuration by switching to the directory containing that configuration (using cd , for example) and then importing the remote object named steve-backup_vault to whichever resource will now be considered to be managing that object:

terraform import aws_backup_vault.example steve-backup_vault

Hi @peter.j.k,

For this particular question I think it would be best to contact the support team, because if you let them know your organization name and workspace name they should be able to determine what situation your state is currently in and then suggest the safest way to recover. I’m hesitant to make suggestions directly here because I can’t be certain what the circumstances are and I wouldn’t want to suggest something that would make the situation worse rather than better.

We are on the FREE as in beer version, so I pinged my manager to, buy support. TY!

1 Like