-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathNew-ALZEnvironment.ps1
More file actions
75 lines (61 loc) · 3.6 KB
/
New-ALZEnvironment.ps1
File metadata and controls
75 lines (61 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
function New-ALZEnvironment {
<#
.SYNOPSIS
This function prompts a user for configuration values and modifies the ALZ Bicep configuration files accordingly.
.DESCRIPTION
This function will prompt the user for commonly used deployment configuration settings and modify the configuration in place.
.PARAMETER alzBicepSource
The directory containing the ALZ-Bicep source repo.
.PARAMETER alzEnvironmentDestination
The directory where the ALZ environment will be created.
.PARAMETER alzBicepVersion
The version of the ALZ-Bicep module to use.
.PARAMETER alzIacProvider
The IaC provider to use for the ALZ environment.
.EXAMPLE
New-ALZEnvironment
.EXAMPLE
New-ALZEnvironment
.EXAMPLE
New-ALZEnvironment -alzEnvironmentDestination "."
.EXAMPLE
New-ALZEnvironment -alzEnvironmentDestination "." -alzBicepVersion "v0.14.0"
#>
[CmdletBinding(SupportsShouldProcess = $true)]
param (
[Parameter(Mandatory = $false)]
[Alias("Output")]
[Alias("OutputDirectory")]
[Alias("O")]
[string] $alzEnvironmentDestination = ".",
[Parameter(Mandatory = $false)]
[string] $alzBicepVersion = "v0.14.0",
[Parameter(Mandatory = $false)]
[ValidateSet("bicep", "terraform")]
[Alias("Iac")]
[string] $alzIacProvider = "bicep"
)
Write-InformationColored "Getting ready to create a new ALZ environment with you..." -ForegroundColor Green -InformationAction Continue
if ($alzIacProvider -eq "terraform") {
Write-InformationColored "Terraform is not yet supported." -ForegroundColor Red -InformationAction Continue
return
}
if ($PSCmdlet.ShouldProcess("ALZ-Bicep module configuration", "modify")) {
$bicepConfig = Get-ALZBicepConfig -alzBicepVersion $alzBicepVersion
New-ALZDirectoryEnvironment -alzEnvironmentDestination $alzEnvironmentDestination | Out-String | Write-Verbose
$alzEnvironmentDestinationInternalCode = Join-Path $alzEnvironmentDestination "upstream-releases"
Get-ALZGithubRelease -directoryForReleases $alzEnvironmentDestinationInternalCode -githubRepoUrl $bicepConfig.module_url -releases @($bicepConfig.version) | Out-String | Write-Verbose
Write-InformationColored "Copying ALZ-Bicep module to $alzEnvironmentDestinationInternalCode" -ForegroundColor Green -InformationAction Continue
Copy-ALZParametersFile -alzEnvironmentDestination $alzEnvironmentDestination -upstreamReleaseDirectory $(Join-Path $alzEnvironmentDestinationInternalCode $bicepConfig.version) -configFiles $bicepConfig.config_files | Out-String | Write-Verbose
Write-InformationColored "ALZ-Bicep source directory: $alzBicepSourceDirectory" -ForegroundColor Green -InformationAction Continue
$configuration = Request-ALZEnvironmentConfig -configurationParameters $bicepConfig.parameters
Set-ComputedConfiguration -configuration $configuration | Out-String | Write-Verbose
Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination $alzEnvironmentDestination -configuration $configuration | Out-String | Write-Verbose
Build-ALZDeploymentEnvFile -configuration $configuration -Destination $alzEnvironmentDestination | Out-String | Write-Verbose
$isGitRepo = Test-ALZGitRepository -alzEnvironmentDestination $alzEnvironmentDestination
if (-not $isGitRepo) {
Write-InformationColored "The directory $alzEnvironmentDestination is not a git repository. Please make it is a git repo after initialization." -ForegroundColor Red -InformationAction Continue
}
}
return
}