-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDeployToAzure.ps1
102 lines (82 loc) · 3.26 KB
/
DeployToAzure.ps1
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# This script deploys the project to Azure
#
# Usage:
#
# .\DeployToAzure.ps1 `
# -ResourceNameMeronym <resource name meronym> `
# -Environment {dev, test, prod} `
# {-UseServiceEndpoints} {-NoCode}
#
# -UseServiceEndpoints flag will provision storage accounts with service endpoints as private connectivity method
# instead of private endpoints. Note that latter (private endpoints) is the recommended option.
#
# Tested to work with Azure CLI version 2.56.0
Param(
[Parameter(Mandatory, HelpMessage="Resource name meronym (lowercase alphanumeric, max length 2)")][string]$ResourceNameMeronym,
[string]$Environment = "dev",
[switch]$UseServiceEndpoints,
[switch]$NoCode = $false
)
$ErrorActionPreference = "Stop"
if ($ResourceNameMeronym.Length -ne 2) {
Write-Error "Invalid argument: Resource name meronym has invalid length - must be exactly 2"
exit 1
}
Write-Output "" # Newline
try {
Write-Output "Retrieving signed in user information..."
$SignedInUserInformation = (az ad signed-in-user show | ConvertFrom-Json)
Write-Output "Retrieving current subscription information..."
$AccountInformation = (az account show | ConvertFrom-Json)
}
catch {
Write-Error "Failed to retrieve the information of the signed in user or the account: ${_}"
exit 1
}
$UserObjectId = $SignedInUserInformation.id
$UserDisplayName = $SignedInUserInformation.displayName
$UserPrincipalName = $SignedInUserInformation.userPrincipalName
$SubscriptionId = $AccountInformation.id
$SubscriptionName = $AccountInformation.name
if ($UserObjectId.Length -ne 36) {
Write-Error "Failed to retrieve the information of the signed in user"
exit 1
}
if ($SubscriptionId.Length -ne 36) {
Write-Error "Failed to retrieve the Azure subscription information"
exit 1
}
Write-Output "`nUsing the following subscription and identity to deploy the project:"
Write-Output " - Subscription: ${SubscriptionName} (${SubscriptionId})"
Write-Output " - Signed in user: ${UserDisplayName}`n - User principal name: ${UserPrincipalName}`n - Object ID: ${UserObjectId}"
if ($UseServiceEndpoints -eq $true) {
Write-Output "" # Newline
Write-Warning "Using service endpoints instead of private endpoints for private connectivity method."
}
$Confirmation = Read-Host "`nAre you sure you want to proceed (y/n)?"
if ($Confirmation.ToLower() -ne 'y' -and $Confirmation.ToLower() -ne 'yes') {
Write-Output "Aborting"
exit 0
}
Write-Output "`nStarting deployment..."
if ($UseServiceEndpoints -eq $true) {
.\New-BicepDeployment.ps1 `
-ResourceNameMeronym $ResourceNameMeronym `
-Environment $Environment `
-SubscriptionId $SubscriptionId `
-UserObjectId $UserObjectId `
-UseServiceEndpoints
} else {
.\New-BicepDeployment.ps1 `
-ResourceNameMeronym $ResourceNameMeronym `
-Environment $Environment `
-SubscriptionId $SubscriptionId `
-UserObjectId $UserObjectId
}
Write-Output "`nUploading blobs..."
.\New-Blobs.ps1 -ResourceNameMeronym $ResourceNameMeronym -Environment $Environment
if ($NoCode -eq $false) {
Write-Output "`nStarting code deployment..."
.\New-CodeDeployment.ps1 -ResourceNameMeronym $ResourceNameMeronym -Environment $Environment
Write-Output "`nFinished"
}