Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ function Get-AcceleratorConfigPath {
}
"bicep" {
$inputConfigFilePaths += "$ConfigFolderPath/platform-landing-zone.yaml"
foreach ($folderName in @("templates", ".config")) {
$folderPath = "$ConfigFolderPath/$folderName"
if (Test-Path $folderPath -PathType Container) {
$starterAdditionalFiles += $folderPath
}
}
}
# bicep-classic and others just use inputs.yaml
}
Expand Down
29 changes: 15 additions & 14 deletions src/ALZ/Private/Deploy-Accelerator-Helpers/New-Bootstrap.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -241,20 +241,6 @@ function New-Bootstrap {
}
}

# Copy additional files
foreach ($additionalFile in $starterAdditionalFiles) {
if (Test-Path $additionalFile -PathType Container) {
$folderName = ([System.IO.DirectoryInfo]::new($additionalFile)).Name
$destination = Join-Path -Path $starterRootModuleFolderPath -ChildPath $folderName
Write-Verbose "Copying folder $additionalFile to $destination"
Copy-Item -Path "$additionalFile/*" -Destination $destination -Recurse -Force
} else {
$fileName = [System.IO.Path]::GetFileName($additionalFile)
$destination = Join-Path -Path $starterRootModuleFolderPath -ChildPath $fileName
Write-Verbose "Copying file $additionalFile to $destination"
Copy-Item -Path $additionalFile -Destination $destination -Force
}
}
}

if ($iac -like "bicep*") {
Expand Down Expand Up @@ -282,6 +268,21 @@ function New-Bootstrap {
Remove-UnrequiredFileSet -path $starterModulePath -foldersOrFilesToRetain $foldersOrFilesToRetain -subFoldersOrFilesToRemove $subFoldersOrFilesToRemove -writeVerboseLogs:$writeVerboseLogs.IsPresent
}

# Copy additional files
foreach ($additionalFile in $starterAdditionalFiles) {
if (Test-Path $additionalFile -PathType Container) {
$folderName = ([System.IO.DirectoryInfo]::new($additionalFile)).Name
$destination = Join-Path -Path $starterRootModuleFolderPath -ChildPath $folderName
Write-Verbose "Copying folder $additionalFile to $destination"
Copy-Item -Path "$additionalFile/*" -Destination $destination -Recurse -Force
} else {
$fileName = [System.IO.Path]::GetFileName($additionalFile)
$destination = Join-Path -Path $starterRootModuleFolderPath -ChildPath $fileName
Write-Verbose "Copying file $additionalFile to $destination"
Copy-Item -Path $additionalFile -Destination $destination -Force
}
}

# Running terraform init and apply
Write-ToConsoleLog "Thank you for providing those inputs, we are now initializing and applying Terraform to bootstrap your environment..." -IsSuccess

Expand Down
6 changes: 3 additions & 3 deletions src/ALZ/Public/New-AcceleratorFolderStructure.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ function New-AcceleratorFolderStructure {

"bicep" = @{
repoName = "alz-bicep-accelerator"
folderToClone = ""
libraryFolderPath = ""
folderToClone = "/"
libraryFolderPath = "templates"
exampleFolderPath = "examples"
bootstrapExampleFolderPath = "bootstrap"
hasScenarios = $false
hasLibrary = $false
hasLibrary = $true
platformLandingZoneFilePath = "platform-landing-zone.yaml"
}

Expand Down
41 changes: 41 additions & 0 deletions src/Tests/Unit/Private/Get-AcceleratorConfigPath.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#-------------------------------------------------------------------------
Set-Location -Path $PSScriptRoot
#-------------------------------------------------------------------------
$ModuleName = 'ALZ'
$PathToManifest = [System.IO.Path]::Combine('..', '..', '..', $ModuleName, "$ModuleName.psd1")
#-------------------------------------------------------------------------
if (Get-Module -Name $ModuleName -ErrorAction 'SilentlyContinue') {
Remove-Module -Name $ModuleName -Force
}
Import-Module $PathToManifest -Force
#-------------------------------------------------------------------------

InModuleScope 'ALZ' {
Describe 'Get-AcceleratorConfigPath Function Tests' -Tag Unit {
It 'returns the bicep configuration files and existing additional folders' {
$configFolderPath = Join-Path $TestDrive 'config'
New-Item -Path (Join-Path $configFolderPath 'templates') -ItemType Directory -Force | Out-Null
New-Item -Path (Join-Path $configFolderPath '.config') -ItemType Directory -Force | Out-Null

$result = Get-AcceleratorConfigPath -ConfigFolderPath $configFolderPath -IacType 'bicep'

$result.InputConfigFilePaths | Should -Be @(
"$configFolderPath/inputs.yaml"
"$configFolderPath/platform-landing-zone.yaml"
)
$result.StarterAdditionalFiles | Should -Be @(
"$configFolderPath/templates"
"$configFolderPath/.config"
)
}

It 'does not return missing bicep additional folders' {
$configFolderPath = Join-Path $TestDrive 'config-without-additional-folders'
New-Item -Path $configFolderPath -ItemType Directory -Force | Out-Null

$result = Get-AcceleratorConfigPath -ConfigFolderPath $configFolderPath -IacType 'bicep'

$result.StarterAdditionalFiles | Should -BeNullOrEmpty
}
}
}
44 changes: 44 additions & 0 deletions src/Tests/Unit/Public/New-AcceleratorFolderStructure.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#-------------------------------------------------------------------------
Set-Location -Path $PSScriptRoot
#-------------------------------------------------------------------------
$ModuleName = 'ALZ'
$PathToManifest = [System.IO.Path]::Combine('..', '..', '..', $ModuleName, "$ModuleName.psd1")
#-------------------------------------------------------------------------
if (Get-Module -Name $ModuleName -ErrorAction 'SilentlyContinue') {
Remove-Module -Name $ModuleName -Force
}
Import-Module $PathToManifest -Force
#-------------------------------------------------------------------------

InModuleScope 'ALZ' {
Describe 'New-AcceleratorFolderStructure Function Tests' -Tag Unit {
BeforeEach {
$script:copyOperations = @()
Mock -CommandName git
Mock -CommandName Copy-Item -MockWith {
$script:copyOperations += [pscustomobject]@{
Path = $Path
Destination = $Destination
Recurse = $Recurse.IsPresent
Force = $Force.IsPresent
}
}
Mock -CommandName Write-ToConsoleLog
}

It 'copies bicep templates into the generated config folder' {
$targetFolderPath = Join-Path $TestDrive 'accelerator'

New-AcceleratorFolderStructure -iacType 'bicep' -targetFolderPath $targetFolderPath

$templateCopy = $script:copyOperations | Where-Object {
$_.Path -match '[/\\]templates$'
}
$templateCopy.Path | Should -HaveCount 1
[System.IO.Path]::GetFileName($templateCopy.Path) | Should -Be 'templates'
$templateCopy.Destination | Should -Be "$targetFolderPath/config"
$templateCopy.Recurse | Should -BeTrue
$templateCopy.Force | Should -BeTrue
}
}
}
Loading