Skip to content

Commit e6d3bf0

Browse files
Fix local override folder function (#106)
# Pull Request ## Description This is a bug fix for the override folder parameters. These are only required for e2e testing or customisation. ## License By submitting this pull request, I confirm that my contribution is made under the terms of the projects associated license.
1 parent 6728899 commit e6d3bf0

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

src/ALZ/Private/New-FolderStructure.ps1

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,38 @@ function New-FolderStructure {
1414
[string] $targetFolder,
1515

1616
[Parameter(Mandatory = $false)]
17-
[string] $sourceFolder
17+
[string] $sourceFolder,
18+
19+
[Parameter(Mandatory = $false)]
20+
[string] $overrideSourceDirectoryPath = ""
1821
)
1922

2023
if ($PSCmdlet.ShouldProcess("ALZ-Terraform module configuration", "modify")) {
2124
Write-Verbose "Downloading modules to $targetDirectory"
25+
2226
if(!($release.StartsWith("v")) -and ($release -ne "latest")) {
2327
$release = "v$release"
2428
}
2529

26-
$releaseTag = Get-GithubRelease -githubRepoUrl $url -targetDirectory $targetDirectory -moduleSourceFolder $sourceFolder -moduleTargetFolder $targetFolder -release $release
27-
$path = Join-Path $targetDirectory $targetFolder $releaseTag
30+
$releaseTag = ""
31+
$path = ""
32+
33+
if($overrideSourceDirectoryPath -ne "") {
34+
$releaseTag = "local"
35+
$path = Join-Path $targetDirectory $targetFolder $releaseTag
36+
37+
if(Test-Path $path) {
38+
Write-Verbose "Folder $path already exists, so not copying files."
39+
} else {
40+
Write-InformationColored "Copying files from $overrideSourceDirectoryPath to $path" -ForegroundColor Green -InformationAction Continue
41+
New-Item -Path $path -ItemType "Directory"
42+
Copy-Item -Path "$overrideSourceDirectoryPath/$sourceFolder/*" -Destination "$path" -Recurse | Out-String | Write-Verbose
43+
}
44+
45+
} else {
46+
$releaseTag = Get-GithubRelease -githubRepoUrl $url -targetDirectory $targetDirectory -moduleSourceFolder $sourceFolder -moduleTargetFolder $targetFolder -release $release
47+
$path = Join-Path $targetDirectory $targetFolder $releaseTag
48+
}
2849

2950
Write-Verbose "Version $releaseTag is located in $path"
3051

src/ALZ/Public/New-ALZEnvironment.ps1

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,11 @@ function New-ALZEnvironment {
142142
}
143143

144144
# Download the bootstrap modules
145-
$bootstrapReleaseTag = "local"
146-
$bootstrapPath = $bootstrapModuleOverrideFolderPath
145+
$bootstrapReleaseTag = ""
146+
$bootstrapPath = ""
147147
$bootstrapTargetFolder = "bootstrap"
148148

149-
if($bootstrapModuleOverrideFolderPath -eq "" -and !$isLegacyBicep) {
149+
if(!$isLegacyBicep) {
150150
$versionAndPath = $null
151151

152152
Write-InformationColored "Checking and Downloading the bootstrap module..." -ForegroundColor Green -NewLineBefore -InformationAction Continue
@@ -159,7 +159,8 @@ function New-ALZEnvironment {
159159
-url $bootstrapModuleUrl `
160160
-release $bootstrapRelease `
161161
-targetFolder $bootstrapTargetFolder `
162-
-sourceFolder $bootstrapSourceFolder
162+
-sourceFolder $bootstrapSourceFolder `
163+
-overrideSourceDirectoryPath $bootstrapModuleOverrideFolderPath
163164
}
164165
$bootstrapReleaseTag = $versionAndPath.releaseTag
165166
$bootstrapPath = $versionAndPath.path
@@ -234,10 +235,10 @@ function New-ALZEnvironment {
234235
}
235236

236237
# Download the starter modules
237-
$starterReleaseTag = "local"
238-
$starterPath = $starterModuleOverrideFolderPath
238+
$starterReleaseTag = ""
239+
$starterPath = ""
239240

240-
if($starterModuleOverrideFolderPath -eq "" -and ($hasStarterModule -or $isLegacyBicep)) {
241+
if(($hasStarterModule -or $isLegacyBicep)) {
241242
$versionAndPath = $null
242243

243244
Write-InformationColored "Checking and Downloading the starter module..." -ForegroundColor Green -NewLineBefore -InformationAction Continue
@@ -250,7 +251,8 @@ function New-ALZEnvironment {
250251
-url $starterModuleUrl `
251252
-release $starterRelease `
252253
-targetFolder $starterModuleTargetFolder `
253-
-sourceFolder $starterModuleSourceFolder
254+
-sourceFolder $starterModuleSourceFolder `
255+
-overrideSourceDirectoryPath $starterModuleOverrideFolderPath
254256
}
255257

256258
$starterReleaseTag = $versionAndPath.releaseTag

0 commit comments

Comments
 (0)