Skip to content

Commit 097486c

Browse files
authored
fix a bug that provider crashes when loading azure schema (#295)
1 parent 86c8b1a commit 097486c

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ FEATURES:
66
ENHANCEMENTS:
77

88
BUG FIXES:
9+
- Fix a bug that provider crashes when loading azure schema.
910

1011
## v1.6.0
1112
FEATURES:

internal/azure/loader.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"log"
88
"sort"
99
"strings"
10+
"sync"
1011

1112
"github.com/Azure/terraform-provider-azapi/internal/azure/types"
1213
)
@@ -16,7 +17,11 @@ var schema *Schema
1617
//go:embed generated
1718
var StaticFiles embed.FS
1819

20+
var mutex = &sync.Mutex{}
21+
1922
func GetAzureSchema() *Schema {
23+
mutex.Lock()
24+
defer mutex.Unlock()
2025
if schema == nil {
2126
data, err := StaticFiles.ReadFile("generated/index.json")
2227
if err != nil {

internal/provider/provider.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"log"
77
"os"
88
"strings"
9-
"sync"
109

1110
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
1211
"github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud"
@@ -308,10 +307,7 @@ func providerConfigure(p *schema.Provider) schema.ConfigureContextFunc {
308307
}
309308

310309
// load schema
311-
var mutex sync.Mutex
312-
mutex.Lock()
313310
azure.GetAzureSchema()
314-
mutex.Unlock()
315311
return client, nil
316312
}
317313
}

0 commit comments

Comments
 (0)