Skip to content

Commit

Permalink
add internal lock to serialize terraform init to avoid potential prov…
Browse files Browse the repository at this point in the history
…ider plugin cache concurrent error
  • Loading branch information
lonegunmanb committed May 27, 2024
1 parent 3382edc commit 3bf523b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions e2etest.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"os"
"path/filepath"
"sync"
"testing"
"time"

Expand All @@ -24,6 +25,7 @@ type TestOptions struct {
}

var copyLock = &KeyedMutex{}
var initLock = &sync.Mutex{}

type TerraformOutput = map[string]interface{}

Expand Down Expand Up @@ -108,6 +110,8 @@ func initAndApply(t terratest.TestingT, options *terraform.Options) string {
}

func tfInit(t terratest.TestingT, options *terraform.Options) {
initLock.Lock()
defer initLock.Unlock()
terraform.Init(t, options)
}

Expand Down
6 changes: 5 additions & 1 deletion version_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ func (s *TestVersionSnapshot) load(t *testing.T) {
NoColor: true,
Logger: logger.Discard,
}
if output, err := initE(t, &opts); err != nil {
if output, err := func() (string, error) {
initLock.Lock()
defer initLock.Unlock()
return initE(t, &opts)
}(); err != nil {
s.Success = false
s.ErrorMsg = output
return
Expand Down

0 comments on commit 3bf523b

Please sign in to comment.