So sometimes my internet likes to cutoff midway, and recently it did so during an apply run of terraform. Is there a way to somehow resume from this? It created some sort of lock file on my local and I was wondering if I could somehow resume from that or start over at least?
Hi @deama,
There is no way to resume a failed apply. In many situations it’s possible to just start a new run and have Terraform learn from the prior state what succeeded and what failed, but whether that will work for you depends on whether Terraform was able to save the state.
If you are using local-only state then you hopefully have an up-to-date state snapshot on your local disk and so you should have everything you need to run terraform apply
again and have it work on anything it didn’t complete in the first run.
If you are using remote state and so Terraform wasn’t able to reach the state storage service in order to save the state, you may be in a situation that is more difficult to recover from. However, typically as a last resort of Terraform cannot save the state to a remote service it will create a local file called errored.tfstate
in the current working directory and announce that it did so in an error message displayed before exiting. If you are in that situation then you could potentially now push that file up to your state storage backend in order to recover, although I would suggest making a backup copy of your current remote state first if you aren’t using a backend configuration that automatically preserves earlier versions:
# save the current remote state to a file,
# just in case this isn't the right approach.
terraform state pull >old.tfstate
# push the errored.tfstate file up as the new
# latest state snapshot
terraform state push errored.tfstate
# now run Terraform as normal, where it shoul
# react to the partially-updated state you
# just submitted
terraform apply