Skip to content

Commit 1d12eef

Browse files
author
netevert
committed
interim commit
1 parent f2e2a2f commit 1d12eef

File tree

4 files changed

+51
-87
lines changed

4 files changed

+51
-87
lines changed

lab/files/create-ad.ps1

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
$adminpassword=$args[0]
2+
$domain=$args[1]
3+
$netname=$args[2]
4+
15
# Making sure all names are resolved
26
Resolve-DnsName github.com
37
Resolve-DnsName raw.githubusercontent.com
@@ -39,7 +43,6 @@ Start-Process -FilePath "$sysmonPath" -ArgumentList "-accepteula -i $sysmonConfi
3943
Write-Host "$('[{0:HH:mm}]' -f (Get-Date)) Verifying that the Sysmon service is running..."
4044
Start-Sleep 5 # Give the service time to start
4145

42-
4346
# Purpose: Installs chocolatey package manager, then installs custom utilities from Choco and adds syntax highlighting for Powershell, Batch, and Docker. Also installs Mimikatz into c:\Tools\Mimikatz.
4447

4548
If (-not (Test-Path "C:\ProgramData\chocolatey")) {
@@ -106,18 +109,9 @@ c:\Windows\SysWOW64\OneDriveSetup.exe /uninstall
106109
Write-Host "Running Update-Help..."
107110
Update-Help -Force -ErrorAction SilentlyContinue
108111

109-
Write-Host "Removing Microsoft Store, Mail, and Edge shortcuts from the taskbar..."
110-
$appname = "Microsoft Edge"
111-
((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() | ?{$_.Name -eq $appname}).Verbs() | ?{$_.Name.replace('&','') -match 'Unpin from taskbar'} | %{$_.DoIt(); $exec = $true}
112-
$appname = "Microsoft Store"
113-
((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() | ?{$_.Name -eq $appname}).Verbs() | ?{$_.Name.replace('&','') -match 'Unpin from taskbar'} | %{$_.DoIt(); $exec = $true}
114-
$appname = "Mail"
115-
((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() | ?{$_.Name -eq $appname}).Verbs() | ?{$_.Name.replace('&','') -match 'Unpin from taskbar'} | %{$_.DoIt(); $exec = $true}
116-
117-
118112
# Provision domain
119113
Import-Module ADDSDeployment
120-
$password = ConvertTo-SecureString "{your_admin_password}" -AsPlainText -Force
114+
$password = ConvertTo-SecureString $adminpassword -AsPlainText -Force
121115
Add-WindowsFeature -name ad-domain-services -IncludeManagementTools
122-
Install-ADDSForest -CreateDnsDelegation:$false -DomainMode Win2012R2 -DomainName "{your_domain}" -DomainNetbiosName "{your_netbios_name}" -ForestMode Win2012R2 -InstallDns:$true -SafeModeAdministratorPassword $password -Force:$true
116+
Install-ADDSForest -CreateDnsDelegation:$false -DomainMode Win2012R2 -DomainName $domain -DomainNetbiosName $netname -ForestMode Win2012R2 -InstallDns:$true -SafeModeAdministratorPassword $password -Force:$true
123117
shutdown -r -t 10

lab/files/install-utilities.ps1

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
$fulldomain=$args[0]
2+
$adminpassword=$args[1]
3+
$adminusername=$args[2]
4+
15
# Making sure all names are resolved
26
Resolve-DnsName github.com
37
Resolve-DnsName raw.githubusercontent.com
@@ -114,8 +118,8 @@ $appname = "Microsoft Store"
114118
$appname = "Mail"
115119
((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() | ?{$_.Name -eq $appname}).Verbs() | ?{$_.Name.replace('&','') -match 'Unpin from taskbar'} | %{$_.DoIt(); $exec = $true}
116120

117-
$domain = "{your_domain}"
118-
$password = "{your_admin_password}" | ConvertTo-SecureString -asPlainText -Force
119-
$username = "$domain\{your_admin_user}"
121+
$domain = $fulldomain
122+
$password = $adminpassword | ConvertTo-SecureString -asPlainText -Force
123+
$username = $adminusername
120124
$credential = New-Object System.Management.Automation.PSCredential($username,$password)
121125
Add-Computer -DomainName $domain -Credential $credential

lab/main.tf

Lines changed: 23 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
provider "azurerm" {
2-
version = "=1.38.0"
3-
2+
features {}
43
subscription_id = var.authentication.subscription_id
54
client_id = var.authentication.client_id
65
client_secret = var.authentication.client_secret
@@ -12,15 +11,15 @@ resource "azurerm_virtual_network" "vnet" {
1211
name = "${var.prefix}-vnet"
1312
address_space = ["10.0.0.0/16"]
1413
location = var.location
15-
resource_group_name = "${var.prefix}"
14+
resource_group_name = var.prefix
1615
tags = var.tags
1716
}
1817

1918
# Create network security group and rules
2019
resource "azurerm_network_security_group" "nsg" {
2120
name = "${var.prefix}-nsg"
2221
location = var.location
23-
resource_group_name = "${var.prefix}"
22+
resource_group_name = var.prefix
2423
tags = var.tags
2524
depends_on = [azurerm_virtual_network.vnet]
2625

@@ -100,67 +99,28 @@ resource "azurerm_network_security_group" "nsg" {
10099
# Create lab subnet
101100
resource "azurerm_subnet" "subnet" {
102101
name = "${var.prefix}-subnet"
103-
resource_group_name = "${var.prefix}"
102+
resource_group_name = var.prefix
104103
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"]
107105
depends_on = [azurerm_network_security_group.nsg]
108106
}
109107

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-
148108
# Create public ip for domain controller 1
149109
resource "azurerm_public_ip" "dc1_publicip" {
150110
name = "${var.workstations.dc1}-external"
151111
location = var.location
152-
resource_group_name = "${var.prefix}"
112+
resource_group_name = var.prefix
153113
allocation_method = "Dynamic"
154114
tags = var.tags
155-
depends_on = [azurerm_storage_blob.adblob]
115+
depends_on = [azurerm_subnet.subnet]
116+
// depends_on = [azurerm_storage_blob.adblob]
156117
}
157118

158119
# Create network interface for domain controller 1
159120
resource "azurerm_network_interface" "dc1_nic" {
160121
name = "${var.workstations.dc1}-primary"
161122
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
164124
tags = var.tags
165125

166126
ip_configuration {
@@ -176,8 +136,8 @@ resource "azurerm_network_interface" "dc1_nic" {
176136
resource "azurerm_virtual_machine" "dc1" {
177137
name = var.workstations.dc1
178138
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]
181141
vm_size = var.workstations.vm_size
182142
tags = var.tags
183143

@@ -222,38 +182,36 @@ resource "azurerm_virtual_machine" "dc1" {
222182
# Create active directory domain forest
223183
resource "azurerm_virtual_machine_extension" "create_ad" {
224184
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
228186
publisher = "Microsoft.Compute"
229187
type = "CustomScriptExtension"
230188
type_handler_version = "1.9"
231189
tags = var.tags
232-
settings = <<SETTINGS
190+
protected_settings = <<PROT
233191
{
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}"
236194
}
237-
SETTINGS
195+
PROT
238196
depends_on = [azurerm_virtual_machine.dc1]
239197
}
240198

241199
# Create public IP for workstation 1
242200
resource "azurerm_public_ip" "pc1_publicip" {
243201
name = "${var.workstations.pc1}-external"
244202
location = var.location
245-
resource_group_name = "${var.prefix}"
203+
resource_group_name = var.prefix
246204
allocation_method = "Dynamic"
247205
tags = var.tags
206+
// depends_on = [azurerm_virtual_machine.dc1]
248207
depends_on = [azurerm_virtual_machine_extension.create_ad]
249208
}
250209

251210
# Create network interface for workstation 1
252211
resource "azurerm_network_interface" "pc1_nic" {
253212
name = "${var.workstations.pc1}-primary"
254213
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
257215
tags = var.tags#
258216
ip_configuration {
259217
name = "${var.workstations.pc1}-nic-conf"
@@ -268,8 +226,8 @@ resource "azurerm_network_interface" "pc1_nic" {
268226
resource "azurerm_virtual_machine" "pc1" {
269227
name = var.workstations.pc1
270228
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]
273231
vm_size = var.workstations.vm_size
274232
tags = var.tags
275233

@@ -314,17 +272,15 @@ resource "azurerm_virtual_machine" "pc1" {
314272
# Install utilities on workstation 1 and join domain
315273
resource "azurerm_virtual_machine_extension" "utils_pc1" {
316274
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
320276
publisher = "Microsoft.Compute"
321277
type = "CustomScriptExtension"
322278
type_handler_version = "1.9"
323279
tags = var.tags
324280
settings = <<SETTINGS
325281
{
326282
"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}
328284
}
329285
SETTINGS
330286
depends_on = [azurerm_storage_blob.utilsblob]

lab/variables.tf

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1+
terraform {
2+
required_providers {
3+
azurerm = {
4+
source = "hashicorp/azurerm"
5+
version = "=2.40.0"
6+
}
7+
}
8+
}
9+
10+
111
variable "authentication" {
2-
type = "map"
12+
type = map(string)
313

414
default = {
515
subscription_id = ""
@@ -12,7 +22,7 @@ variable "authentication" {
1222
variable "location" {}
1323

1424
variable "accounts" {
15-
type = "map"
25+
type = map(string)
1626

1727
default = {
1828
# workstation accounts
@@ -22,7 +32,7 @@ variable "accounts" {
2232
}
2333

2434
variable "workstations" {
25-
type = "map"
35+
type = map(string)
2636

2737
default = {
2838
# Image configurations
@@ -38,12 +48,12 @@ variable "workstations" {
3848
}
3949

4050
variable "prefix" {
41-
type = "string"
51+
type = string
4252
default = "testlab"
4353
}
4454

4555
variable "tags" {
46-
type = "map"
56+
type = map(string)
4757

4858
default = {
4959
environment = "testing"

0 commit comments

Comments
 (0)