Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
369 views
in Technique[技术] by (71.8m points)

continuous integration - Is there a way to work with multiple workspaces in parallel?

In a Continuous Integration setup (Jenkins) I'd like to deploy (terraform apply) changes of the same Terraform configuration code using multiple workspaces at the same time using the same copy of the repository - i.e. the very same directory with .tf files.

Stages are executed in parallel (on same node/agent) and each of them consists of the same sequence of operations (terraform workspace select and then terraform apply).

It doesn't seem supported as the attempts fail with lock errors, e.g.

# terraform workspace select "workspace1"
# terraform apply [...] -input=false -auto-approve

 Switched to workspace "workspace1".
 Acquiring state lock. This may take a few moments...
 
 Error: Error locking state: Error acquiring the state lock: ConditionalCheckFailedException: The conditional request failed
 Lock Info:
   ID:        52973611-a892-deac-985b-5aa28172fdaf
   Path:      my-project/env:/workspace5/state
   Operation: OperationTypeApply
   Who:       @87ddd2118473
   Version:   0.13.5
   Created:   2021-01-11 15:20:06.635256155 +0000 UTC
   Info:      

So it looks like lock for workspace5 gets in the way for applying for workspace1.

Is there any way out?

I use:

  • Terraform 0.13.5
  • s3 as the backend
  • DynamoDB for locks

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

One idea I have (which seems to work) is to copy the whole codebase to a separate directory. I.e. each workspace to be applied to each own. And run terraform workspace select and terraform apply from separate copies.

It works. But it's lame (inefficient).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
...