boltops-tools / terraspace

Terraspace: The Terraform Framework
https://terraspace.cloud
Apache License 2.0
674 stars 46 forks source link

terraspace all down runs init multiple times on the same stack resulting in error locking state #271

Open exoaturner opened 1 year ago

exoaturner commented 1 year ago

Checklist

My Environment

Software Version
Operating System Ubuntu 20.04
Terraform v1.3.1
Terraspace v2.2.2
Ruby v3.1.2

Expected Behaviour

When terraspace all down --yes --exit-on-fail runs, it calls terraform init -get -input=false for each stack and only once.

Current Behavior

When terraspace all down --yes --exit-on-fail runs, it calls terraform init -get -input=false for each stack.

Currently the theory is the terraform init gets called or runs twice in parallel for the same stack, this is because of duplicate initializations found in the init logs for stacks.

This results in a failure: "Error locking state: Error acquiring the state lock Error message: resource temporary unavailable".

This seems to be resolvable by running terraspace all init --yes --exit-on-fail before the destroy.

Step-by-step reproduction instructions

Run terraspace all down --yes --exit-on-fail on a project in a clean environment/workspace without any terraspace all init.

Code Sample

Sadly can't provide a code sample from the project.

Solution Suggestion

I attempted to look into the function that calls the terraform init but I can't see how it would ever run twice in parallel resulting in this issues.