-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path7_vm-dc2.tf.disable
75 lines (68 loc) · 3.05 KB
/
7_vm-dc2.tf.disable
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
// NOTE: Step four is to create my first Domain Controller
locals {
virtual_machine_name_dc2 = "${var.dc2}"
virtual_machine_fqdn_dc2 = "${var.dc2}.${var.active_directory_domain}"
custom_data_params_dc2 = "Param($RemoteHostName = \"${local.virtual_machine_fqdn_dc2}\", $ComputerName = \"${local.virtual_machine_name_dc2}\")"
custom_data_content_dc2 = "${local.custom_data_params_dc2} ${file("${path.module}/files/winrm.ps1")}"
}
resource "azurerm_network_interface" "dc2" {
name = "${var.dc2}-nic"
location = "${var.azlocation}"
resource_group_name = "${var.RG_Network}"
internal_dns_name_label = "${local.virtual_machine_name_dc2}"
depends_on = ["azurerm_subnet.Server"]
ip_configuration {
name = "dc2"
subnet_id = "${azurerm_subnet.Server.id}"
private_ip_address_allocation = "static"
private_ip_address = "172.31.2.12"
}
}
resource "azurerm_virtual_machine" "domain-controler2" {
name = "${local.virtual_machine_name_dc2}"
location = "${var.azlocation}"
resource_group_name = "${var.RG_Compute}"
vm_size = "Standard_D2s_v3"
network_interface_ids = ["${element(azurerm_network_interface.dc2.*.id, count.index)}"]
delete_os_disk_on_termination = true
depends_on = ["azurerm_network_interface.dc2"]
storage_image_reference {
publisher = "MicrosoftWindowsServer"
offer = "WindowsServer"
sku = "2019-Datacenter"
version = "latest"
}
storage_os_disk {
name = "${local.virtual_machine_name_dc2}-C"
caching = "ReadWrite"
create_option = "FromImage"
vhd_uri = "${azurerm_storage_account.storlrs.primary_blob_endpoint}vhds/${var.dc2}-C.vhd"
}
boot_diagnostics {
enabled = true
storage_uri = "${azurerm_storage_account.storlrsdiag.primary_blob_endpoint}"
}
os_profile {
computer_name = "${local.virtual_machine_name_dc2}"
admin_username = "${var.admin_username}"
admin_password = "${var.admin_password}"
custom_data = "${local.custom_data_content_dc2}"
}
os_profile_windows_config {
provision_vm_agent = true
enable_automatic_upgrades = true
additional_unattend_config {
pass = "oobeSystem"
component = "Microsoft-Windows-Shell-Setup"
setting_name = "AutoLogon"
content = "<AutoLogon><Password><Value>${var.admin_password}</Value></Password><Enabled>true</Enabled><LogonCount>1</LogonCount><Username>${var.admin_username}</Username></AutoLogon>"
}
# Unattend config is to enable basic auth in WinRM, required for the provisioner stage.
additional_unattend_config {
pass = "oobeSystem"
component = "Microsoft-Windows-Shell-Setup"
setting_name = "FirstLogonCommands"
content = "${file("${path.module}/files/FirstLogonCommands.xml")}"
}
}
}