-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy path02_01_SimpleIaas.ps1
75 lines (61 loc) · 2.18 KB
/
02_01_SimpleIaas.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
Set-Location c:\
Clear-Host
#Install Az Module
Install-Module -Name Az -AllowClobber -Force -Verbose
#Import Az Module and Authenticate to Azure
Import-Module -Name Az
#Log into Azure
Connect-AzAccount
#Select the correct subscription
Get-AzSubscription -SubscriptionName "MSDN Platforms" | Select-AzSubscription
Get-AzContext
#Define Deployment Variables
$appNamePrefix = 'tws'
$resourceGroupName = "$appNamePrefix-simple-iaas"
$resourceGroupLocation = 'westeurope'
$resourceProviderNamespace = 'Microsoft.Network'
$resourceTypeName = 'virtualNetworks'
$vNetName = "vnet-$appNamePrefix"
$vNetAddressPrefix = '172.16.0.0/16'
$vNetSubnet1Name = 'subnet-1'
$vNetSubnet1Prefix = '172.16.1.0/24'
$vNetSubnet2Name = 'subnet-2'
$vNetSubnet2Prefix = '172.16.2.0/24'
$randomString = ([char[]]([char]'a'..[char]'z') + 0..9 | Sort-Object {Get-Random})[0..8] -join ''
$storageAccountNamePrefix = 'storage'
$storageAccountType = 'Standard_LRS'
$storageAccountName = $storageAccountNamePrefix + ($storageAccountType.Replace('Standard_','')).ToLower() + $randomString
#Get ARM Provider Locations
((Get-AzResourceProvider `
-ProviderNamespace "$resourceProviderNamespace").ResourceTypes | `
Where-Object {$_.ResourceTypeName -eq "$resourceTypeName"}).Locations | `
Sort-Object
#Create ARM Resource Group
$resourceGroup = New-AzResourceGroup `
-Name $resourceGroupName `
-Location $resourceGroupLocation `
-Verbose -Force
#Create Virtual Network Subnets
$vNetSubnet1 = New-AzVirtualNetworkSubnetConfig `
-Name $vNetSubnet1Name `
-AddressPrefix $vNetSubnet1Prefix `
-Verbose
$vNetSubnet2 = New-AzVirtualNetworkSubnetConfig `
-Name $vNetSubnet2Name `
-AddressPrefix $vNetSubnet2Prefix `
-Verbose
#Create Virtual Network
New-AzVirtualNetwork `
-ResourceGroupName $resourceGroup.ResourceGroupName `
-Location $resourceGroup.Location `
-Name $vNetName `
-AddressPrefix $vNetAddressPrefix `
-Subnet $vNetSubnet1,$vNetSubnet2 `
-Verbose -Force
#Create Storage Account
New-AzStorageAccount `
-ResourceGroupName $resourceGroup.ResourceGroupName `
-Location $resourceGroup.Location `
-Name $storageAccountName `
-Type $storageAccountType `
-Verbose