I am using terraform open source for creating and managing GCP resources. While performing terraform apply, I have issued control+c twice and it has corrupted the state-file as per the given warnings.
I wanted to know the possible ways to recover from this.
Lets say I have 5 rss defined in TF file. and while 5th rss is being created if I issue control+c twice. Terraform apply will exit immediately and state file will not have that rss but it will be created in GCP project.
Subsequent apply commands are waiting for a long time(30min) to report that the rss already exist. and destroy will not touch the rss as it is not in the state-file.
The only possible option seems to be deleting the rss manually or import it to the state file via terraform import command. I want to handle this scenario in an automated fashion.
You might say dont issue control+c while terraform apply, but there may be situations like:
- What if I want to stop the execution in middle for some reason?
- If am running terraform from a GCP compute engine, and it crashes which is more or less like control+c interrupts. I have tested the scenario.
- If am running terraform on a cloudbuild, and wanted to stop it for some reason?
I tried with both local and remote state-files:
local: State-file data loss happened, refresh is not getting the orphaned rss which was created as part of initial terraform apply which was interrupted twice. terraform apply for the second run hangs on creating the same rss and after 30~40 mins it says it already exists.
Remote: Initial cancelled terraform run holds the lock on the state-file, subsequent runs have to be run only by passing -lock=false option(which is not recommended), which immediately says all rss exists.
so how can we handle these scenarios? If terraform can’t handle it can we say its tool reliability issue or how to address?