With gitlab ci, ,my tests will use a bash script to ssh into a vagrant vm that is responsible for running a terraform deployment.
In the event a test must be cancelled from the Gitlab CI UI, this almost always results in a corrupted tfstate file. This is because the ssh connection is killed almost immediately.
I’ve also found the backup isn’t always usable in this scenario either, and its not something I’d like to rely on.
What other alternatives are there? Possible paths of enquiry I’ve had are:
- Is it possible to get terraform to automatically import all resources that match a tag? That way I could recover from a new state perhaps.
- Or could terraform actions be deployed via a service that would continue or stop the process nicely if the ssh connection ended?
- is there some other way to repair a corrupted file, or more aggresively backup / checkpoint a file? if a tfstate file gets busted, it needs to get repaired automtically somehow.