Skip to content

Commit c19fc5f

Browse files
Correct parameters for copy file (#7)
## Description Correct the parameters file so we can copyu the destination files. ## License By submitting this pull request, I confirm that my contribution is made under the terms of the projects associated license. --------- Co-authored-by: Guy Pritchard MSFT <111762521+lovelysandwich@users.noreply.github.com>
1 parent 2867847 commit c19fc5f

File tree

8 files changed

+125
-15
lines changed

8 files changed

+125
-15
lines changed

src/ALZ/Assets/alz-bicep-config/v0.13.0.config.json

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,53 @@
22
"version": "v0.13.0",
33
"module_url": "https://github.com/Azure/ALZ-Bicep",
44
"config_files": [
5+
{
6+
"source": "infra-as-code/bicep/modules/policy/definitions/parameters/customPolicyDefinitions.parameters.all.json",
7+
"destination": "config/custom-parameters/customPolicyDefinitions.parameters.json"
8+
},
9+
{
10+
"source": "infra-as-code/bicep/modules/customRoleDefinitions/parameters/customRoleDefinitions.parameters.all.json",
11+
"destination": "config/custom-parameters/customRoleDefinitions.parameters.json"
12+
},
13+
{
14+
"source": "infra-as-code/bicep/modules/hubNetworking/parameters/hubNetworking.parameters.all.json",
15+
"destination": "config/custom-parameters/hubNetworking.parameters.json"
16+
},
17+
{
18+
"source": "infra-as-code/bicep/modules/logging/parameters/logging.parameters.all.json",
19+
"destination": "config/custom-parameters/logging.parameters.json"
20+
},
21+
{
22+
"source": "infra-as-code/bicep/modules/managementGroups/parameters/managementGroups.parameters.all.json",
23+
"destination": "config/custom-parameters/managementGroups.parameters.json"
24+
},
25+
{
26+
"source": "infra-as-code/bicep/modules/mgDiagSettings/parameters/mgDiagSettings.parameters.all.json",
27+
"destination": "config/custom-parameters/mgDiagSettings.parameters.json"
28+
},
29+
{
30+
"source": "infra-as-code/bicep/modules/policy/assignments/parameters/policyAssignmentManagementGroup.dine.parameters.all.json",
31+
"destination": "config/custom-parameters/policyAssignmentManagementGroup.dine.parameters.json"
32+
},
533
{
634
"source": "infra-as-code/bicep/modules/resourceGroup/parameters/resourceGroup.parameters.all.json",
7-
"detination": "config/resourceGroup.parameters.json"
35+
"destination": "config/custom-parameters/resourceGroupConnectivity.parameters.json"
836
},
937
{
10-
"source": "infra-as-code/bicep/modules/policy/definitions/parameters/customPolicyDefinitions.parameters.all.json",
11-
"destination": "config/customPolicyDefinitions.parameters.json"
38+
"source": "infra-as-code/bicep/modules/resourceGroup/parameters/resourceGroup.parameters.all.json",
39+
"destination": "config/custom-parameters/resourceGroupLoggingAndSentinel.parameters.json"
40+
},
41+
{
42+
"source": "infra-as-code/bicep/modules/roleAssignments/parameters/roleAssignmentManagementGroupMany.servicePrincipal.parameters.all.json",
43+
"destination": "config/custom-parameters/roleAssignmentManagementGroupMany.servicePrincipal.parameters.json"
44+
},
45+
{
46+
"source": "infra-as-code/bicep/modules/subscriptionPlacement/parameters/subscriptionPlacement.parameters.all.json",
47+
"destination": "config/custom-parameters/subscriptionPlacement.parameters.json"
48+
},
49+
{
50+
"source": "infra-as-code/bicep/modules/vwanConnectivity/parameters/vwanConnectivity.parameters.all.json",
51+
"destination": "config/custom-parameters/vwanConnectivity.parameters.json"
1252
}
1353
],
1454
"parameters": {

src/ALZ/Private/Build-ALZDeploymentEnvFile.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ function Build-ALZDeploymentEnvFile {
1919

2020
$envFile = Join-Path $destination ".env"
2121

22-
New-Item -Path $envFile -ItemType file -Force | Out-Null
22+
New-Item -Path $envFile -ItemType file -Force | Out-String | Write-Verbose
2323

2424
foreach ($configurationValue in $configuration.PsObject.Properties) {
2525
foreach ($target in $configurationValue.Value.Targets) {
2626
if ($target.Destination -eq "Environment") {
27-
Add-Content -Path $envFile -Value "$($($target.Name))=`"$($configurationValue.Value.Value)`"" | Out-Null
27+
Add-Content -Path $envFile -Value "$($($target.Name))=`"$($configurationValue.Value.Value)`"" | Out-String | Write-Verbose
2828
}
2929
}
3030
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
function Copy-ALZParametersFile {
2+
[CmdletBinding(SupportsShouldProcess = $true)]
3+
param (
4+
[Parameter(Mandatory = $true)]
5+
[Alias("Output")]
6+
[Alias("OutputDirectory")]
7+
[Alias("O")]
8+
[string] $alzEnvironmentDestination,
9+
10+
[Parameter(Mandatory = $true)]
11+
[string]$upstreamReleaseDirectory,
12+
13+
[Parameter(Mandatory = $true)]
14+
[array]$configFiles
15+
)
16+
foreach ($configFile in $configFiles) {
17+
$sourcePath = Join-Path $upstreamReleaseDirectory $configFile.source
18+
$destinationPath = Join-Path $alzEnvironmentDestination $configFile.destination
19+
if (Test-Path $sourcePath) {
20+
if ($PSCmdlet.ShouldProcess($sourcePath, "Copy")) {
21+
# create destination folder if it does not exists
22+
$destinationFolder = Split-Path -Path $destinationPath -Parent
23+
if (-not (Test-Path $destinationFolder)) {
24+
New-Item -ItemType Directory -Path $destinationFolder -Force | Out-String | Write-Verbose
25+
}
26+
Copy-Item -Path $sourcePath -Destination $destinationPath -Recurse -Force | Out-String | Write-Verbose
27+
}
28+
} else {
29+
Write-Warning "The file $sourcePath does not exist."
30+
}
31+
}
32+
}

src/ALZ/Private/Get-GithubRelease.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ function Get-GithubRelease {
120120
Move-Item -Path "$($extractedSubFolder.FullName)/*" -Destination "$releaseDirectory" -ErrorAction SilentlyContinue | Out-String | Write-Verbose
121121
}
122122

123-
# Remove-Item -Path "$releaseDirectory/tmp" -Force -Recurse
123+
Remove-Item -Path "$releaseDirectory/tmp" -Force -Recurse
124124

125125
} else {
126126
Write-Verbose "===> Content already exists in $releaseDirectory. Skipping"

src/ALZ/Private/New-ALZDirectoryEnvironment.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ function New-ALZDirectoryEnvironment {
1313
$configModules = Join-Path $alzEnvironmentDestination "config" "modules"
1414
$upstream = Join-Path $alzEnvironmentDestination "upstream-releases"
1515

16-
New-Item -ItemType Directory -Path $alzEnvironmentDestination -Force | Out-Null
17-
New-Item -ItemType Directory -Path $gitHubPipeline -Force | Out-Null
18-
New-Item -ItemType Directory -Path $config -Force | Out-Null
19-
New-Item -ItemType Directory -Path $upstream -Force | Out-Null
20-
New-Item -ItemType Directory -Path $configModules -Force | Out-Null
16+
New-Item -ItemType Directory -Path $alzEnvironmentDestination -Force | Out-String | Write-Verbose
17+
New-Item -ItemType Directory -Path $gitHubPipeline -Force | Out-String | Write-Verbose
18+
New-Item -ItemType Directory -Path $config -Force | Out-String | Write-Verbose
19+
New-Item -ItemType Directory -Path $upstream -Force | Out-String | Write-Verbose
20+
New-Item -ItemType Directory -Path $configModules -Force | Out-String | Write-Verbose
2121

2222
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
function Test-ALZGitRepository {
2+
[CmdletBinding(SupportsShouldProcess = $true)]
3+
param (
4+
[Parameter(Mandatory = $true)]
5+
[Alias("Output")]
6+
[Alias("OutputDirectory")]
7+
[Alias("O")]
8+
[string] $alzEnvironmentDestination
9+
)
10+
$gitDirectory = Join-Path $alzEnvironmentDestination ".git"
11+
if (Test-Path $gitDirectory) {
12+
Write-Verbose "The directory $alzEnvironmentDestination is already a git repository."
13+
return $true
14+
}
15+
$gitInit = Read-Host "Initialize the directory $alzEnvironmentDestination as a git repository? (y/n)"
16+
if ($gitInit -ieq "y" -and $PSCmdlet.ShouldProcess("gitrepository", "initialize")) {
17+
git init $alzEnvironmentDestination
18+
return $true
19+
}
20+
return $false
21+
}

src/ALZ/Public/New-ALZEnvironment.ps1

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,23 @@ function New-ALZEnvironment {
4949

5050
$bicepConfig = Get-ALZBicepConfig -alzBicepVersion $alzBicepVersion
5151

52-
New-ALZDirectoryEnvironment -alzEnvironmentDestination $alzEnvironmentDestination | Out-Null
52+
New-ALZDirectoryEnvironment -alzEnvironmentDestination $alzEnvironmentDestination | Out-String | Write-Verbose
5353

5454
$alzEnvironmentDestinationInternalCode = Join-Path $alzEnvironmentDestination "upstream-releases"
55-
Get-GithubRelease -directoryForReleases $alzEnvironmentDestinationInternalCode -githubRepoUrl $bicepConfig.module_url -releases @($bicepConfig.version) | Out-Null
55+
Get-GithubRelease -directoryForReleases $alzEnvironmentDestinationInternalCode -githubRepoUrl $bicepConfig.module_url -releases @($bicepConfig.version) | Out-String | Write-Verbose
5656
Write-InformationColored "Copying ALZ-Bicep module to $alzEnvironmentDestinationInternalCode" -ForegroundColor Green -InformationAction Continue
57+
Copy-ALZParametersFile -alzEnvironmentDestination $alzEnvironmentDestination -upstreamReleaseDirectory $(Join-Path $alzEnvironmentDestinationInternalCode $bicepConfig.version) -configFiles $bicepConfig.config_files | Out-String | Write-Verbose
5758
Write-InformationColored "ALZ-Bicep source directory: $alzBicepSourceDirectory" -ForegroundColor Green -InformationAction Continue
5859

5960
$configuration = Request-ALZEnvironmentConfig -configurationParameters $bicepConfig.parameters
6061

61-
Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination $alzEnvironmentDestination -configuration $configuration | Out-Null
62-
Build-ALZDeploymentEnvFile -configuration $configuration -Destination $alzEnvironmentDestination | Out-Null
62+
Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination $alzEnvironmentDestination -configuration $configuration | Out-String | Write-Verbose
63+
Build-ALZDeploymentEnvFile -configuration $configuration -Destination $alzEnvironmentDestination | Out-String | Write-Verbose
64+
65+
$isGitRepo = Test-ALZGitRepository -alzEnvironmentDestination $alzEnvironmentDestination
66+
if (-not $isGitRepo) {
67+
Write-InformationColored "The directory $alzEnvironmentDestination is not a git repository. Please make it is a git repo after initialization." -ForegroundColor Red -InformationAction Continue
68+
}
6369
}
6470

6571
return $true

src/Tests/Unit/Public/New-ALZEnvironment.Tests.ps1

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ InModuleScope 'ALZ' {
4949
@{
5050
"module_url" = "test"
5151
"version" = "v1.0.0"
52+
"config_files" = @(
53+
@{
54+
"source" = "a"
55+
"destination" = "b"
56+
}
57+
)
5258
"parameters" = @{
5359
"test" = @{
5460
"type" = "string"
@@ -59,7 +65,12 @@ InModuleScope 'ALZ' {
5965

6066
Mock -CommandName Get-GithubRelease -MockWith { }
6167

68+
Mock -CommandName Test-ALZGitRepository -MockWith { $false }
69+
70+
Mock -CommandName Copy-ALZParametersFile -MockWith { }
71+
6272
Mock -CommandName Write-InformationColored
73+
6374
}
6475

6576
It 'should return the output directory on completion' {

0 commit comments

Comments
 (0)