-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathBuild-ALZDeploymentEnvFile.ps1
More file actions
33 lines (28 loc) · 1.07 KB
/
Build-ALZDeploymentEnvFile.ps1
File metadata and controls
33 lines (28 loc) · 1.07 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
function Build-ALZDeploymentEnvFile {
param (
[Parameter(Mandatory = $true)]
[PSCustomObject] $configuration,
[Parameter(Mandatory = $false)]
[string] $destination = "."
)
<#
.SYNOPSIS
This function uses configuration to build a .env file for use in the deployment pipeline.
.EXAMPLE
Build-ALZDeploymentEnvFile -configuration configuration
.EXAMPLE
Build-ALZDeploymentEnvFile -configuration configuration -destination "."
.OUTPUTS
N/A
#>
$envFile = Join-Path $destination ".env"
New-Item -Path $envFile -ItemType file -Force | Out-String | Write-Verbose
foreach ($configurationValue in $configuration.PsObject.Properties) {
foreach ($target in $configurationValue.Value.Targets) {
if ($target.Destination -eq "Environment") {
$formattedValue = $configurationValue.Value.Value
Add-Content -Path $envFile -Value "$($($target.Name))=`"$formattedValue`"" | Out-String | Write-Verbose
}
}
}
}