-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdpi30.ps1
149 lines (136 loc) · 5.94 KB
/
dpi30.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<#
.Synopsis
DPi30 Decision and Deployment Tree
.Description
Script that will walk you through determining the proper DPi30 Template and help you deploy it step by step.
#>
#Included files to make our script significantly more readable.
$IncludeScripts =
"$PSScriptRoot/includes/validation.ps1",
"$PSScriptRoot/includes/determinetemplate.ps1",
"$PSScriptRoot/includes/deployresourcegroup.ps1",
"$PSScriptRoot/includes/deploymoderndatawarehouse.ps1",
"$PSScriptRoot/includes/deploysimple.ps1",
"$PSScriptRoot/includes/deploymanagedinstance.ps1"
foreach ($script in $IncludeScripts) {
try {
. ($script)
}
catch {
Write-Error "Error loading $script" -ErrorAction Stop
}
}
#try {
# . ("$PSScriptRoot/includes/validation.ps1")
# . ("$PSScriptRoot/includes/determinetemplate.ps1")
# . ("$PSScriptRoot/includes/deployresourcegroup.ps1")
# . ("$PSScriptRoot/includes/deploymoderndatawarehouse.ps1")
# . ("$PSScriptRoot/includes/deploysimple.ps1")
# . ("$PSScriptRoot/includes/deploymanagedinstance.ps1")
#}
#catch {
# Write-Error "Error while loading supporting PowerShell Scripts" -ErrorAction Stop
#}
function DeployTemplate {
# Moved initial deployment tree to secondary function to allow for easier expansion if we have more templates in the future
Param(
# The Template name we intend to deploy
$template
)
Clear-Host
# Create our resource group to deploy our azure resources to
$resourceGroupInformation = DeployResourceGroup
if ($template -eq "moderndatawarehouse") {
DeployDWTemplate -ResourceGroupName $resourceGroupInformation.ResourceGroupName -DataFactoryRegion $resourceGroupInformation.DataFactoryRegion
}
if ($template -eq "simple") {
DeploySimpleTemplate -ResourceGroupName $resourceGroupInformation.ResourceGroupName -DataFactoryRegion $resourceGroupInformation.DataFactoryRegion
}
if ($template -eq "managedinstance") {
DeployManagedInstanceTemplate -ResourceGroupName $resourceGroupInformation.ResourceGroupName -DataFactoryRegion $resourceGroupInformation.DataFactoryRegion
}
}
function SubscriptionSelection {
$InputMessage = "`r`nSubscription number"
$SubSelection = Read-Host $InputMessage
$valid = IntValidation -UserInput $SubSelection
while(!($valid.Result)) {
Write-Host $valid.Message -ForegroundColor Yellow
$SubSelection = Read-Host $InputMessage
$valid = IntValidation -UserInput $SubSelection
}
while([int32]$SubSelection -ge $subcount) {
Write-Host "Please select a valid subscription number, $SubSelection is not an option" -ForegroundColor Yellow
$SubSelection = SubscriptionSelection
}
return $SubSelection
}
# Our code entry point, We verify the subscription and move through the steps from here.
Clear-Host
$currentsub = Get-AzContext
$currentsubfull = $currentsub.Subscription.Name + " (" + $currentsub.Subscription.Id + ")"
Write-Host "Welcome to the DPi30 Deployment Wizard!"
Write-Host "Before we get started, we need to select the subscription for this deployment:`r`n"
#Gathering subscription selection, validating input and changing to another subscription if needed
$rawsubscriptionlist = Get-AzSubscription | Where-Object {$_.State -ne "Disabled"} | Sort-Object -property Name | Select-Object Name, Id
$subscriptionlist = [ordered]@{}
$subscriptionlist.Add(1, "CURRENT SUBSCRIPTION: $($currentsubfull)")
$subcount = 2
foreach ($subscription in $rawsubscriptionlist) {
$subname = $subscription.Name + " (" + $subscription.Id + ")"
if($subname -ne $currentsubfull) {
$subscriptionlist.Add($subcount, $subname)
$subcount++
}
}
$subscriptionlist.GetEnumerator() | ForEach-Object { Write-Host "$($_.Key))" "$($_.Value)"}
$InputMessage = "`r`nSubscription number"
$SubSelection = Read-Host $InputMessage
$valid = IntValidation -UserInput $SubSelection -OptionCount $subscriptionlist.Count
while(!($valid.Result)) {
Write-Host $valid.Message -ForegroundColor Yellow
$SubSelection = Read-Host $InputMessage
$valid = IntValidation -UserInput $SubSelection -OptionCount $subscriptionlist.Count
}
if ($SubSelection -ne 1) {
$selectedsub = $subscriptionlist.[int]$SubSelection
$selectedsubid = $selectedsub.Substring($selectedsub.Length - 37).TrimEnd(")")
$changesub = Select-AzSubscription -Subscription $selectedsubid
Write-Host "`r`nSuccessfully changed to Subscription $($changesub.Name)" -ForegroundColor Green
} else {
Write-Host "`r`nContinuing with current Subscription $($currentsubfull)" -ForegroundColor Green
}
Start-Sleep -s 2 #Quick sleep before a new section and clear host
#Printing template based upon responses and confirming whether to proceed
Clear-Host
$template = DetermineTemplate
switch ($template) {
"moderndatawarehouse" {
$templatedescription = $datawarehousedescription
$templatetype = "Modern Data Warehouse"
break
}
"simple" {
$templatedescription = $simpledescription
$templatetype = "Azure SQL Database"
break
}
"managedinstance" {
$templatedescription = $managedinstancedescription
$templatetype = "Azure SQL Managed Instance"
break
}
}
Write-Host "`r`nBased on your answers we suggest the deployment of " -NoNewLine
Write-Host $templatetype -ForegroundColor Cyan
Write-Host "This template will deploy the following to your Azure Subscription: " -NoNewLine
Write-Host "$currentsubfull`r`n" -ForegroundColor Cyan
Write-Host $templatedescription -ForegroundColor Cyan
$confirmation = ProceedValidation
if ($confirmation -eq "y") {
Write-Host "`r`nProceeding with the $($templatetype) deployment template" -ForegroundColor Green
Start-Sleep -s 2 #Quick sleep before a new section and clear host
DeployTemplate -template $template
} else {
exit
}