Skip to content

Commit

Permalink
fix: mutex for tft init
Browse files Browse the repository at this point in the history
  • Loading branch information
apeabody committed Feb 9, 2024
1 parent b098e68 commit 5cf77e6
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions infra/blueprint-test/pkg/tft/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"path"
"path/filepath"
"strings"
"sync"
gotest "testing"
"time"

Expand Down Expand Up @@ -73,6 +74,7 @@ type TFBlueprintTest struct {
verify func(*assert.Assertions) // verify function
teardown func(*assert.Assertions) // teardown function
setupOutputOverrides map[string]interface{} // override outputs from the Setup phase
mutex *sync.Mutex // Mutex to protect Terraform init
}

type tftOption func(*TFBlueprintTest)
Expand Down Expand Up @@ -447,7 +449,10 @@ func (b *TFBlueprintTest) DefaultVerify(assert *assert.Assertions) {

// DefaultInit runs TF init and validate on a blueprint.
func (b *TFBlueprintTest) DefaultInit(assert *assert.Assertions) {
// mutex to prevent parallel calls to Terraform init as plugin cache isn't concurrent safe
b.mutex.Lock()
terraform.Init(b.t, b.GetTFOptions())
b.mutex.Unlock()
// if vars are set for common options, this seems to trigger -var flag when calling validate
// using custom tfOptions as a workaround
terraform.Validate(b.t, terraform.WithDefaultRetryableErrors(b.t, &terraform.Options{
Expand Down

0 comments on commit 5cf77e6

Please sign in to comment.