-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuildDevEnvironment.ps1
255 lines (219 loc) · 8.73 KB
/
BuildDevEnvironment.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
$configData = Import-PowerShellDataFile -Path '.\configdata.psd1'
<#
Tools
Connect to the Service
Connect-AzAccount - this causes the console to hang at the moment - bug?
Connect to Jump VM
$jumppip = (Get-AzPublicIpAddress -ResourceGroupName $configData.ResourceGroupName -Name 'JumpPIP').IpAddress
mstsc /v:"$jumppip" /admin
Cleanup Tasks
Remove-AzResourceGroup -Name $configData.ResourceGroupName -Force -Verbose -AsJob
#>
# Build Resource Group
New-AzResourceGroup -ResourceGroupName $configData.ResourceGroupName -Location $configData.Location
#region Subnets
# Define the Remote Subnet - for external access and admin
$remoteSubnetSplat = @{
Name = $configData.Remote.SubnetName
AddressPrefix = $configData.Remote.SubnetPrefix
}
$remoteSubnet = New-AzVirtualNetworkSubnetConfig @remoteSubnetSplat -Verbose
# Define the WSM (Master Domain) Subnet
$wsmSubnetSplat = @{
Name = $configData.WSM.SubnetName
AddressPrefix = $configData.WSM.SubnetPrefix
}
$wsmSubnet = New-AzVirtualNetworkSubnetConfig @wsmSubnetSplat -Verbose
# Define the Portishead Subnet
$portisheadSubnetSplat = @{
Name = $configData.Portishead.SubnetName
AddressPrefix = $configData.Portishead.SubnetPrefix
}
$portisheadSubnet = New-AzVirtualNetworkSubnetConfig @portisheadSubnetSplat -Verbose
# Define the Winscombe Subnet
$winscombeSubnetSplat = @{
Name = $configData.Winscombe.SubnetName
AddressPrefix = $configData.Winscombe.SubnetPrefix
}
$winscombeSubnet = New-AzVirtualNetworkSubnetConfig @winscombeSubnetSplat -Verbose
# Build the VNet to encapsulate the above Subnets
$vnetSplat = @{
ResourceGroupName = $configData.ResourceGroupName
Location = $configData.Location
Name = $configData.VnetName
AddressPrefix = $configData.VnetPrefix
Subnet = $remoteSubnet, $wsmSubnet, $portisheadSubnet, $winscombeSubnet
}
$vnet = New-AzVirtualNetwork @vnetSplat -Verbose
#endregion Subnets
#region Networking
# Defining Internal Network Security Rules
$ruleAllInboundAllowSplat = @{
Name = 'internalcomms-rule-inbound'
Description = 'Allow All Internal Comms Inbound'
Access = 'Allow'
Protocol = 'Tcp'
Direction = 'Inbound'
Priority = 100
SourceAddressPrefix = '192.168.0.0/16'
SourcePortRange = '*'
DestinationAddressPrefix = '*'
DestinationPortRange = '*'
}
$ruleAllInboundAllow = New-AzNetworkSecurityRuleConfig @ruleAllInboundAllowSplat
#region RemoteNetworking
# Create a Public IP for the Jump Server
$pipSplat = @{
ResourceGroupName = $configData.ResourceGroupName
Location = $configData.Location
AllocationMethod = 'Dynamic'
Name = 'JumpPIP'
}
$pip = New-AzPublicIpAddress @pipSplat -Verbose
# Defining Network Security Rules for Jump Server
$ruleRDPAllowSplat = @{
Name = 'rdp-rule'
Description = 'Allow RDP'
Access = 'Allow'
Protocol = 'Tcp'
Direction = 'Inbound'
Priority = 100
SourceAddressPrefix = 'Internet'
SourcePortRange = '*'
DestinationAddressPrefix = '*'
DestinationPortRange = '3389'
}
$ruleRDPAllow = New-AzNetworkSecurityRuleConfig @ruleRDPAllowSplat
# Building Network Security Group for Jump Server
$nsgRemoteSplat = @{
ResourceGroupName = $configData.ResourceGroupName
Location = $configData.Location
Name = $configData.Remote.NsgName
SecurityRules = $ruleRDPAllow
}
$nsgRemote = New-AzNetworkSecurityGroup @nsgRemoteSplat
# Updating the Vnet Config with the Network Security Group Information
$remoteSubnetConfigSplat = @{
VirtualNetwork = $vnet
Name = $configdata.Remote.SubnetName
AddressPrefix = $configData.Remote.SubnetPrefix
NetworkSecurityGroup = $nsgRemote
}
$remoteSubnetConfig = Set-AzVirtualNetworkSubnetConfig @remoteSubnetConfigSplat -Verbose
#endregion RemoteNetworking
#region WSMNetworking
# Building Network Security Group for WSM Server
$nsgWsmSplat = @{
ResourceGroupName = $configData.ResourceGroupName
Location = $configData.Location
Name = $configData.WSM.NsgName
SecurityRules = $ruleAllInboundAllow
}
$nsgWSM = New-AzNetworkSecurityGroup @nsgWsmSplat
# Updating the Vnet Config with the Network Security Group Information
$wsmSubnetConfigSplat = @{
VirtualNetwork = $vnet
Name = $configdata.WSM.SubnetName
AddressPrefix = $configData.WSM.SubnetPrefix
NetworkSecurityGroup = $nsgWSM
}
$wsmSubnetConfig = Set-AzVirtualNetworkSubnetConfig @wsmSubnetConfigSplat -Verbose
#endregion WSMNetworking
#region WinscombeNetworking
# Building Network Security Group for Winscombe Server
$nsgWinscombeSplat = @{
ResourceGroupName = $configData.ResourceGroupName
Location = $configData.Location
Name = $configData.Winscombe.NsgName
SecurityRules = $ruleAllInboundAllow
}
$nsgWinscombe = New-AzNetworkSecurityGroup @nsgWinscombeSplat
# Updating the Vnet Config with the Network Security Group Information
$winscombeSubnetConfigSplat = @{
VirtualNetwork = $vnet
Name = $configdata.Winscombe.SubnetName
AddressPrefix = $configData.Winscombe.SubnetPrefix
NetworkSecurityGroup = $nsgWinscombe
}
$winscombeSubnetConfig = Set-AzVirtualNetworkSubnetConfig @winscombeSubnetConfigSplat -Verbose
#endregion WinscombeNetworking
#region PortisheadNetworking
# Building Network Security Group for Portishead Server
$nsgPortisheadSplat = @{
ResourceGroupName = $configData.ResourceGroupName
Location = $configData.Location
Name = $configData.Portishead.NsgName
SecurityRules = $ruleAllInboundAllow
}
$nsgPortishead = New-AzNetworkSecurityGroup @nsgPortisheadSplat
# Updating the Vnet Config with the Network Security Group Information
$portisheadSubnetConfigSplat = @{
VirtualNetwork = $vnet
Name = $configdata.Portishead.SubnetName
AddressPrefix = $configData.Portishead.SubnetPrefix
NetworkSecurityGroup = $nsgPortishead
}
$portisheadSubnetConfig = Set-AzVirtualNetworkSubnetConfig @portisheadSubnetConfigSplat -Verbose
#endregion PortisheadNetworking
# Applying the new Vnet Config
Set-AzVirtualNetwork -VirtualNetwork $vnet -Verbose
#endregion Networking
#region BuildVMs
# Building Credential for VMs
$credential = [pscredential]::new($configData.AdminUserName, (ConvertTo-SecureString -String $configData.AdminPassword -asPlainText -Force ))
# Building the Jump VM
$jumpVMSplat = @{
Credential = $credential
Name = $configData.Remote.VmName
PublicIpAddressName = 'JumpPIP'
ResourceGroupName = $configData.ResourceGroupName
Location = $configData.Location
Size = 'Standard_D1'
SubnetName = $configData.Remote.SubnetName
VirtualNetworkName = $configData.VnetName
SecurityGroupName = $configData.Remote.NsgName
AsJob = $true
}
New-AzVM @jumpVMSplat -Verbose
# Building the WSM DC
$wsmVMSplat = @{
Credential = $credential
Name = $configData.WSM.VmName
ResourceGroupName = $configData.ResourceGroupName
Location = $configData.Location
Size = 'Standard_D1'
SubnetName = $configData.WSM.SubnetName
VirtualNetworkName = $configData.VnetName
SecurityGroupName = $configData.WSM.NsgName
AsJob = $true
}
New-AzVM @wsmVMSplat -Verbose
# Building the Winscombe DC
$winscombeVMSplat = @{
Credential = $credential
Name = $configData.Winscombe.VmName
ResourceGroupName = $configData.ResourceGroupName
Location = $configData.Location
Size = 'Standard_D1'
SubnetName = $configData.Winscombe.SubnetName
VirtualNetworkName = $configData.VnetName
SecurityGroupName = $configData.Winscombe.NsgName
AsJob = $true
}
New-AzVM @winscombeVMSplat -Verbose
# Building the Portishead DC
$portisheadVMSplat = @{
Credential = $credential
Name = $configData.Portishead.VmName
ResourceGroupName = $configData.ResourceGroupName
Location = $configData.Location
Size = 'Standard_D1'
SubnetName = $configData.Portishead.SubnetName
VirtualNetworkName = $configData.VnetName
SecurityGroupName = $configData.Portishead.NsgName
AsJob = $true
}
New-AzVM @portisheadVMSplat -Verbose
#endregion BuildVMs
# Monitor each VM creation Job and return results as they complete
Get-Job | Receive-Job -Wait