-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
101 lines (93 loc) · 3.16 KB
/
main.tf
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
data "vsphere_datacenter" "datacenter" {
name = var.vsphere_datacenter
}
data "vsphere_host" "host" {
name = var.vsphere_host
datacenter_id = data.vsphere_datacenter.datacenter.id
}
data "vsphere_network" "network" {
name = var.network
datacenter_id = data.vsphere_datacenter.datacenter.id
}
data "vsphere_virtual_machine" "dc_template" {
name = var.dc_template
datacenter_id = data.vsphere_datacenter.datacenter.id
}
data "vsphere_virtual_machine" "ws_template" {
name = var.ws_template
datacenter_id = data.vsphere_datacenter.datacenter.id
}
# Deploy and provision domain controller
resource "vsphere_virtual_machine" "domain_controller" {
name = var.dc_name
num_cpus = var.cpus
num_cores_per_socket = var.cores
memory = var.memory
resource_pool_id = data.vsphere_host.host.resource_pool_id
guest_id = var.dc_guest_id
scsi_type = local.scsi_type
firmware = local.firmware
efi_secure_boot_enabled = local.secure_boot
network_interface {
network_id = data.vsphere_network.network.id
}
disk {
label = "disk0"
size = var.disk_size
}
clone {
template_uuid = data.vsphere_virtual_machine.dc_template.id
customize {
timeout = local.timeout
windows_options {
computer_name = var.dc_name
}
network_interface {
ipv4_address = var.ipv4_address
ipv4_netmask = var.ipv4_netmask
}
ipv4_gateway = var.ipv4_gateway
}
}
folder = var.folder
provisioner "local-exec" {
command = "ansible-playbook -i '${var.ipv4_address},' ansible/windows_dc/main.yaml --extra-vars 'ansible_user=solaire ansible_password=1qaz2wsx!QAZ@WSX safe_mode_password=${var.dsrm_password} dns_domain_name=${var.dns_domain_name} domain_admin_password=1qaz2wsx!QAZ@WSX'"
}
}
# Deploy and provision windows workstation
resource "vsphere_virtual_machine" "windows_ws" {
depends_on = [vsphere_virtual_machine.domain_controller]
count = var.instances
name = "${var.ws_name}-${count.index}"
num_cpus = var.cpus
num_cores_per_socket = var.cores
memory = var.memory
resource_pool_id = data.vsphere_host.host.resource_pool_id
guest_id = var.ws_guest_id
scsi_type = local.scsi_type
firmware = local.firmware
efi_secure_boot_enabled = local.secure_boot
network_interface {
network_id = data.vsphere_network.network.id
}
disk {
label = "disk0"
size = var.disk_size
}
clone {
template_uuid = data.vsphere_virtual_machine.ws_template.id
customize {
timeout = local.timeout
windows_options {
computer_name = "${var.ws_name}-${count.index}"
join_domain = var.dns_domain_name
domain_admin_user = var.domain_admin_user
domain_admin_password = var.domain_admin_password
}
network_interface {
dns_server_list = [var.ipv4_address]
}
}
}
folder = var.folder
}