-
Notifications
You must be signed in to change notification settings - Fork 7
/
04_02_Deploy-Networking_Teil_1.ps1
68 lines (57 loc) · 2.58 KB
/
04_02_Deploy-Networking_Teil_1.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
#Define Deployment Variables
$appNamePrefix = 'tws'
$locationDetails = Get-Content -Path './locationDetails.json' | ConvertFrom-Json
#Deploy Storage Accounts
foreach ($i in $locationDetails) {
$location = $i.Location
$resourceGroupName = "$appNamePrefix-iaas-$location"
$resourceGroup = Get-AzResourceGroup -Name $resourceGroupName
$resourceGroupId = $resourceGroup.ResourceId
$uniqueString = ((Get-FileHash -InputStream ([System.IO.MemoryStream]::New([System.Text.Encoding]::ASCII.GetBytes($resourceGroupId)))).Hash[0..2] -join '').ToLower()
$storageAccountType = 'Standard_LRS'
$storageAccountName = ($appNamePrefix + 'logs' + $storageAccountType.Replace('Standard_','') + $location + $uniqueString).ToLower()
New-AzStorageAccount `
-ResourceGroupName $resourceGroup.ResourceGroupName `
-Location $resourceGroup.Location `
-Name $storageAccountName `
-Type $storageAccountType
}
#Deploy Network Security Groups
foreach ($i in $locationDetails) {
$location = $i.Location
$vNetName = "$appNamePrefix-vnet-$location"
$resourceGroupName = "$appNamePrefix-iaas-$location"
$vNetAddressPrefix = $i.AddressPrefix
$subnetDetails = $i.Subnets | Where-Object {$_.Name -ne 'GatewaySubnet'}
foreach ($subnet in $subnetDetails) {
$subnetName = $subnet.Name
$subnetPrefix = $subnet.SubnetPrefix
$nsgName = "$subnetName-nsg"
$nsg = New-AzNetworkSecurityGroup `
-Name $nsgName `
-ResourceGroupName $resourceGroupName `
-Location $location `
-Force
$nsgRules = $subnet.NsgRules
foreach ($rule in $nsgRules) {
$nsg | Add-AzNetworkSecurityRuleConfig `
-Name $rule.Name `
-Description $rule.Description `
-Access $rule.Access `
-Protocol $rule.Protocol `
-Direction $rule.Direction `
-Priority $rule.Priority `
-SourceAddressPrefix $rule.SourceAddressPrefix `
-SourcePortRange $rule.SourcePortRange `
-DestinationAddressPrefix $rule.DestinationAddressPrefix `
-DestinationPortRange ($rule.DestinationPortRange).Split(",") | Set-AzNetworkSecurityGroup
}
$vNet = Get-AzVirtualNetwork -Name $vNetName -ResourceGroupName $resourceGroupName
Set-AzVirtualNetworkSubnetConfig `
-Name $subnetName `
-VirtualNetwork $vNet `
-AddressPrefix $subnetPrefix `
-NetworkSecurityGroup $nsg
$vNet | Set-AzVirtualNetwork
}
}