-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGENNETWORKDeploy.ps1
More file actions
112 lines (90 loc) · 3.67 KB
/
GENNETWORKDeploy.ps1
File metadata and controls
112 lines (90 loc) · 3.67 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
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
<#
.SYNOPSIS
Deploys a template to Azure
.DESCRIPTION
Deploys an Azure Resource Manager template
.EXAMPLE
./deploy.ps1 -subscription "Azure Subscription" -resourceGroupName myresourcegroup -resourceGroupLocation centralus
.PARAMETER Subscription
The subscription name or id where the template will be deployed.
.PARAMETER ResourceGroupName
The resource group where the template will be deployed. Can be the name of an existing or a new resource group.
.PARAMETER ResourceGroupLocation
Optional, a resource group location. If specified, will try to create a new resource group in this location. If not specified, assumes resource group is existing.
.PARAMETER TemplateFilePath
Optional, path to the template file. Defaults to template.json.
.PARAMETER ParametersFilePath
Optional, path to the parameters file. Defaults to parameters.json. If file is not found, will prompt for parameter values based on template.
#>
param(
[Parameter(Mandatory=$True)]
[string]
$Subscription,
[Parameter(Mandatory=$True)]
[string]
$ResourceGroupName,
[string]
$ResourceGroupLocation,
[string]
$TemplateFilePath = "azuredeploy.json",
[string]
$ParametersFilePath = "azuredeploy.parameters.json"
)
$AzModuleVersion = "2.0.0"
<#
.SYNOPSIS
Registers RPs
#>
Function RegisterRP {
Param(
[string]$ResourceProviderNamespace
)
Write-Host "Registering resource provider '$ResourceProviderNamespace'";
Register-AzResourceProvider -ProviderNamespace $ResourceProviderNamespace;
}
#******************************************************************************
# Script body
# Execution begins here
#******************************************************************************
$ErrorActionPreference = "Stop"
# Verify that the Az module is installed
if (!(Get-InstalledModule -Name Az -MinimumVersion $AzModuleVersion -ErrorAction SilentlyContinue)) {
Write-Host "This script requires to have Az Module version $AzModuleVersion installed..
It was not found, please install from: https://docs.microsoft.com/en-us/powershell/azure/install-az-ps"
exit
}
# sign in
Write-Host "Logging in...";
Connect-AzAccount;
# select subscription
Write-Host "Selecting subscription '$Subscription'";
Select-AzSubscription -Subscription $Subscription;
# Register RPs
$resourceProviders = @("microsoft.network");
if($resourceProviders.length) {
Write-Host "Registering resource providers"
foreach($resourceProvider in $resourceProviders) {
RegisterRP($resourceProvider);
}
}
#Create or check for existing resource group
$resourceGroup = Get-AzResourceGroup -Name $ResourceGroupName -ErrorAction SilentlyContinue
if(!$resourceGroup)
{
if(!$ResourceGroupLocation) {
Write-Host "Resource group '$ResourceGroupName' does not exist. To create a new resource group, please enter a location.";
$resourceGroupLocation = Read-Host "ResourceGroupLocation";
}
Write-Host "Creating resource group '$ResourceGroupName' in location '$ResourceGroupLocation'";
New-AzResourceGroup -Name $ResourceGroupName -Location $ResourceGroupLocation
}
else{
Write-Host "Using existing resource group '$ResourceGroupName'";
}
# Start the deployment
Write-Host "Starting deployment...";
if(Test-Path $ParametersFilePath) {
New-AzResourceGroupDeployment -ResourceGroupName $ResourceGroupName -TemplateFile $TemplateFilePath -TemplateParameterFile $ParametersFilePath -Name armNETWORKDEPLOYMENT -Verbose;
} else {
New-AzResourceGroupDeployment -ResourceGroupName $ResourceGroupName -TemplateFile $TemplateFilePath -Name armNETWORKDEPLOYMENT -Verbose;
}