diff --git a/infra/blueprint-test/pkg/tft/terraform.go b/infra/blueprint-test/pkg/tft/terraform.go index 24647d70aa80..3ab668ff21bd 100644 --- a/infra/blueprint-test/pkg/tft/terraform.go +++ b/infra/blueprint-test/pkg/tft/terraform.go @@ -24,6 +24,7 @@ import ( "path" "path/filepath" "strings" + "sync" gotest "testing" "time" @@ -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 + tftCacheMutex sync.Mutex // Mutex to protect Terraform plugin cache } type tftOption func(*TFBlueprintTest) @@ -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.tftCacheMutex.Lock() terraform.Init(b.t, b.GetTFOptions()) + b.tftCacheMutex.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{