Skip to content

Commit 3a7b96d

Browse files
authored
feat: add instance atomic to support multiple providers (#211)
1 parent 7d76872 commit 3a7b96d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

initialize.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,18 @@ import (
1111
"net/url"
1212
"os"
1313
"path/filepath"
14+
"strconv"
15+
"sync/atomic"
1416

1517
"github.com/Azure/alzlib/internal/environment"
1618
"github.com/Azure/alzlib/internal/processor"
1719
"github.com/hashicorp/go-getter/v2"
1820
)
1921

22+
// Instance is used to track the current instance ID.
23+
// When set by the caller, it prevents collisions in the .alzlib directory.
24+
var Instance atomic.Uint32
25+
2026
// fetchLibraryWithDependencies takes a library reference, fetches it, and then fetches all of its
2127
// dependencies. The destination directory is an integer that will be appended to the `.alzlib`
2228
// directory in the current working
@@ -113,7 +119,8 @@ func FetchAzureLandingZonesLibraryMember(
113119
// It returns an fs.FS interface to the fetched library to be used in the AlzLib.Init() method.
114120
func FetchLibraryByGetterString(ctx context.Context, getterString, dstDir string) (fs.FS, error) {
115121
baseDir := environment.AlzLibDir()
116-
dst := filepath.Join(baseDir, dstDir)
122+
instance := strconv.Itoa(int(Instance.Load()))
123+
dst := filepath.Join(baseDir, instance, dstDir)
117124
client := getter.Client{
118125
DisableSymlinks: true,
119126
}

0 commit comments

Comments
 (0)