Skip to content

Commit

Permalink
Fix parallel acctest race on Provider
Browse files Browse the repository at this point in the history
We should not initialize providers for every test, in which case it
might cause the global provider not same as the actual used provider in
each test. And might results into panic when user trying to retrive meta
from global provider when testing resource exist/destroy.
  • Loading branch information
magodo authored and tombuildsstuff committed Jan 24, 2020
1 parent dbbd95f commit b9d06e5
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions azurerm/internal/acceptance/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"math"
"os"
"strconv"
"sync"
"testing"

"github.com/Azure/go-autorest/autorest/azure"
Expand All @@ -17,6 +18,8 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/provider"
)

var once sync.Once

type TestData struct {
// Locations is a set of Azure Regions which should be used for this Test
Locations Regions
Expand Down Expand Up @@ -48,13 +51,15 @@ type TestData struct {

// BuildTestData generates some test data for the given resource
func BuildTestData(t *testing.T, resourceType string, resourceLabel string) TestData {
azureProvider := provider.AzureProvider().(*schema.Provider)
once.Do(func() {
azureProvider := provider.AzureProvider().(*schema.Provider)

AzureProvider = azureProvider
SupportedProviders = map[string]terraform.ResourceProvider{
"azurerm": azureProvider,
"azuread": azuread.Provider().(*schema.Provider),
}
AzureProvider = azureProvider
SupportedProviders = map[string]terraform.ResourceProvider{
"azurerm": azureProvider,
"azuread": azuread.Provider().(*schema.Provider),
}
})

env, err := Environment()
if err != nil {
Expand Down

0 comments on commit b9d06e5

Please sign in to comment.