1
1
provider "azurerm" {
2
- version = " =1.38.0"
3
-
2
+ features {}
4
3
subscription_id = var. authentication . subscription_id
5
4
client_id = var. authentication . client_id
6
5
client_secret = var. authentication . client_secret
@@ -12,15 +11,15 @@ resource "azurerm_virtual_network" "vnet" {
12
11
name = " ${ var . prefix } -vnet"
13
12
address_space = [" 10.0.0.0/16" ]
14
13
location = var. location
15
- resource_group_name = " ${ var . prefix } "
14
+ resource_group_name = var. prefix
16
15
tags = var. tags
17
16
}
18
17
19
18
# Create network security group and rules
20
19
resource "azurerm_network_security_group" "nsg" {
21
20
name = " ${ var . prefix } -nsg"
22
21
location = var. location
23
- resource_group_name = " ${ var . prefix } "
22
+ resource_group_name = var. prefix
24
23
tags = var. tags
25
24
depends_on = [azurerm_virtual_network . vnet ]
26
25
@@ -100,67 +99,28 @@ resource "azurerm_network_security_group" "nsg" {
100
99
# Create lab subnet
101
100
resource "azurerm_subnet" "subnet" {
102
101
name = " ${ var . prefix } -subnet"
103
- resource_group_name = " ${ var . prefix } "
102
+ resource_group_name = var. prefix
104
103
virtual_network_name = azurerm_virtual_network. vnet . name
105
- address_prefix = " 10.0.1.0/24"
106
- network_security_group_id = azurerm_network_security_group. nsg . id
104
+ address_prefixes = [" 10.0.1.0/24" ]
107
105
depends_on = [azurerm_network_security_group . nsg ]
108
106
}
109
107
110
- # Create storage account
111
- resource "azurerm_storage_account" "storageaccount" {
112
- name = " ${ var . prefix } sablobstrg01"
113
- resource_group_name = " ${ var . prefix } "
114
- location = var. location
115
- account_tier = " Standard"
116
- account_replication_type = " GRS"
117
- depends_on = [azurerm_subnet . subnet ]
118
- }
119
-
120
- # Create blob storage container for post configuration files
121
- resource "azurerm_storage_container" "blobstorage" {
122
- name = " ${ var . prefix } -store1"
123
- storage_account_name = azurerm_storage_account. storageaccount . name
124
- container_access_type = " blob"
125
- depends_on = [azurerm_storage_account . storageaccount ]
126
- }
127
-
128
- # Create storage blob for install-utilities.ps1 file
129
- resource "azurerm_storage_blob" "utilsblob" {
130
- depends_on = [azurerm_storage_container . blobstorage ]
131
- name = " install-utilities.ps1"
132
- storage_account_name = azurerm_storage_account. storageaccount . name
133
- storage_container_name = azurerm_storage_container. blobstorage . name
134
- type = " block"
135
- source = " ./files/install-utilities.ps1"
136
- }
137
-
138
- # Create storage blob for create-ad.ps1 file
139
- resource "azurerm_storage_blob" "adblob" {
140
- depends_on = [azurerm_storage_blob . utilsblob ]
141
- name = " create-ad.ps1"
142
- storage_account_name = azurerm_storage_account. storageaccount . name
143
- storage_container_name = azurerm_storage_container. blobstorage . name
144
- type = " block"
145
- source = " ./files/create-ad.ps1"
146
- }
147
-
148
108
# Create public ip for domain controller 1
149
109
resource "azurerm_public_ip" "dc1_publicip" {
150
110
name = " ${ var . workstations . dc1 } -external"
151
111
location = var. location
152
- resource_group_name = " ${ var . prefix } "
112
+ resource_group_name = var. prefix
153
113
allocation_method = " Dynamic"
154
114
tags = var. tags
155
- depends_on = [azurerm_storage_blob . adblob ]
115
+ depends_on = [azurerm_subnet . subnet ]
116
+ // depends_on = [azurerm_storage_blob.adblob]
156
117
}
157
118
158
119
# Create network interface for domain controller 1
159
120
resource "azurerm_network_interface" "dc1_nic" {
160
121
name = " ${ var . workstations . dc1 } -primary"
161
122
location = var. location
162
- resource_group_name = " ${ var . prefix } "
163
- network_security_group_id = azurerm_network_security_group. nsg . id
123
+ resource_group_name = var. prefix
164
124
tags = var. tags
165
125
166
126
ip_configuration {
@@ -176,8 +136,8 @@ resource "azurerm_network_interface" "dc1_nic" {
176
136
resource "azurerm_virtual_machine" "dc1" {
177
137
name = var. workstations . dc1
178
138
location = var. location
179
- resource_group_name = " ${ var . prefix } "
180
- network_interface_ids = [" ${ azurerm_network_interface . dc1_nic . id } " ]
139
+ resource_group_name = var. prefix
140
+ network_interface_ids = [azurerm_network_interface . dc1_nic . id ]
181
141
vm_size = var. workstations . vm_size
182
142
tags = var. tags
183
143
@@ -222,38 +182,36 @@ resource "azurerm_virtual_machine" "dc1" {
222
182
# Create active directory domain forest
223
183
resource "azurerm_virtual_machine_extension" "create_ad" {
224
184
name = " create_ad"
225
- location = var. location
226
- resource_group_name = " ${ var . prefix } "
227
- virtual_machine_name = azurerm_virtual_machine. dc1 . name
185
+ virtual_machine_id = azurerm_virtual_machine. dc1 . id
228
186
publisher = " Microsoft.Compute"
229
187
type = " CustomScriptExtension"
230
188
type_handler_version = " 1.9"
231
189
tags = var. tags
232
- settings = << SETTINGS
190
+ protected_settings = << PROT
233
191
{
234
- "fileUris": ["https://${ azurerm_storage_account . storageaccount . name } .blob.core.windows.net/ ${ azurerm_storage_container . blobstorage . name } /create-ad.ps1"],
235
- "commandToExecute": "powershell -ExecutionPolicy Unrestricted -File create-ad.ps1"
192
+ "fileUris": ["https://raw.githubusercontent.com/netevert/scripts/master /create-ad.ps1"],
193
+ "commandToExecute": "powershell -ExecutionPolicy Unrestricted -File create-ad.ps1 ${ var . accounts . dc1_admin_password } ${ var . prefix } .com ${ var . prefix } "
236
194
}
237
- SETTINGS
195
+ PROT
238
196
depends_on = [azurerm_virtual_machine . dc1 ]
239
197
}
240
198
241
199
# Create public IP for workstation 1
242
200
resource "azurerm_public_ip" "pc1_publicip" {
243
201
name = " ${ var . workstations . pc1 } -external"
244
202
location = var. location
245
- resource_group_name = " ${ var . prefix } "
203
+ resource_group_name = var. prefix
246
204
allocation_method = " Dynamic"
247
205
tags = var. tags
206
+ // depends_on = [azurerm_virtual_machine.dc1]
248
207
depends_on = [azurerm_virtual_machine_extension . create_ad ]
249
208
}
250
209
251
210
# Create network interface for workstation 1
252
211
resource "azurerm_network_interface" "pc1_nic" {
253
212
name = " ${ var . workstations . pc1 } -primary"
254
213
location = var. location
255
- resource_group_name = " ${ var . prefix } "
256
- network_security_group_id = azurerm_network_security_group. nsg . id
214
+ resource_group_name = var. prefix
257
215
tags = var. tags #
258
216
ip_configuration {
259
217
name = " ${ var . workstations . pc1 } -nic-conf"
@@ -268,8 +226,8 @@ resource "azurerm_network_interface" "pc1_nic" {
268
226
resource "azurerm_virtual_machine" "pc1" {
269
227
name = var. workstations . pc1
270
228
location = var. location
271
- resource_group_name = " ${ var . prefix } "
272
- network_interface_ids = [" ${ azurerm_network_interface . pc1_nic . id } " ]
229
+ resource_group_name = var. prefix
230
+ network_interface_ids = [azurerm_network_interface . pc1_nic . id ]
273
231
vm_size = var. workstations . vm_size
274
232
tags = var. tags
275
233
@@ -314,17 +272,15 @@ resource "azurerm_virtual_machine" "pc1" {
314
272
# Install utilities on workstation 1 and join domain
315
273
resource "azurerm_virtual_machine_extension" "utils_pc1" {
316
274
name = " utils_pc1"
317
- location = var. location
318
- resource_group_name = " ${ var . prefix } "
319
- virtual_machine_name = azurerm_virtual_machine. pc1 . name
275
+ virtual_machine_id = azurerm_virtual_machine. pc1 . id
320
276
publisher = " Microsoft.Compute"
321
277
type = " CustomScriptExtension"
322
278
type_handler_version = " 1.9"
323
279
tags = var. tags
324
280
settings = << SETTINGS
325
281
{
326
282
"fileUris": ["https://${ azurerm_storage_account . storageaccount . name } .blob.core.windows.net/${ azurerm_storage_container . blobstorage . name } /install-utilities.ps1"],
327
- "commandToExecute": "powershell -ExecutionPolicy Unrestricted -File install-utilities.ps1"
283
+ "commandToExecute": "powershell -ExecutionPolicy Unrestricted -File install-utilities.ps1 ${ var . prefix } .com ${ var . accounts . dc1_admin_password } ${ var . prefix } .com\ ${ var . accounts . dc1_admin_user }
328
284
}
329
285
SETTINGS
330
286
depends_on = [azurerm_storage_blob . utilsblob ]
0 commit comments