Repository navigation
Expand file tree
/
Copy pathDeploy-Infrastructure.ps1
More file actions
67 lines (54 loc) · 1.92 KB
/
Copy pathDeploy-Infrastructure.ps1
File metadata and controls
67 lines (54 loc) · 1.92 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
param
(
[Parameter(Mandatory = $true)]
[string]$DeploymentName,
[Parameter(Mandatory = $true)]
[string]$Location,
[switch]$WhatIf
)
Write-Host "Starting infrastructure deployment..."
Push-Location -Path $PSScriptRoot
$principalId = (az ad signed-in-user show --query id -o tsv)
if ($IsWindows) {
$identityArray = "[{'principalId':'$($principalId)','principalType':'User'}]"
}
else {
$identityArray = '[{"principalId":"' + $($principalId) + '","principalType":"User"}]'
}
if ($WhatIf) {
Write-Host "Previewing infrastructure deployment. No changes will be made."
$result = (az deployment sub what-if `
--name $DeploymentName `
--location $Location `
--template-file '../core.bicep' `
--parameters '../core.bicepparam' `
--parameters workloadName=$DeploymentName `
--parameters location=$Location `
--parameters identities="$identityArray" `
--no-pretty-print) | ConvertFrom-Json
if (-not $result) {
Write-Error "Infrastructure deployment preview failed."
exit 1
}
Write-Host "Infrastructure deployment preview succeeded."
$result.changes | Format-List
exit
}
$deploymentOutputs = (az deployment sub create `
--name $DeploymentName `
--location $Location `
--template-file '../core.bicep' `
--parameters '../core.bicepparam' `
--parameters workloadName=$DeploymentName `
--parameters location=$Location `
--parameters identities="$identityArray" `
--query properties.outputs -o json) | ConvertFrom-Json
if (-not $deploymentOutputs) {
Write-Error "Infrastructure deployment failed."
exit 1
}
Write-Host "Infrastructure deployment succeeded."
$deploymentOutputs | Format-List
$deploymentOutputs | ConvertTo-Json | Out-File -FilePath './InfrastructureOutputs.json' -Encoding utf8
Pop-Location
return $deploymentOutputs