-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
61 lines (52 loc) · 1.96 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
resource "vsphere_virtual_machine" "vm" {
for_each = var.vms
name = each.value.name
datastore_id = data.vsphere_datastore.datastore.id
resource_pool_id = data.vsphere_compute_cluster.compute_cluster.resource_pool_id
guest_id = var.vm_guest_id
num_cpus = var.vm_vcpu
memory = var.vm_memory
firmware = var.vm_firmware
# Primary disk configuration
disk {
label = "${each.value.name}_disk0"
size = each.value.disk0_size
thin_provisioned = var.vm_disk_thin
unit_number = 0
}
# Additional disks configuration
dynamic "disk" {
for_each = each.value.additional_disks
content {
label = join("_", [each.value.name, "disk,${disk.key + 1}"])
size = disk.value.size
thin_provisioned = disk.value.thin_provisioned
unit_number = disk.key + 1 // Ensure unique SCSI unit number
}
}
dynamic "network_interface" {
for_each = each.value.network_interfaces
content {
network_id = lookup(local.network_map, network_interface.value.network_name)
adapter_type = "vmxnet3" // Hardcoded adapter type for simplicity
}
}
clone {
template_uuid = data.vsphere_virtual_machine.template.id
customize {
windows_options {
computer_name = each.value.name
workgroup = var.vm_domain // Need to test with AD at the moment this just changes workgroup, rather than domain join.
}
ipv4_gateway = var.vm_ipv4_gateway
dynamic "network_interface" {
for_each = each.value.network_interfaces
content {
ipv4_address = network_interface.value.vm_ip
ipv4_netmask = network_interface.value.ipv4_netmask
dns_server_list = network_interface.key == 0 ? var.vm_dns_servers : null // Ensures DNS settings only applied to first adapter.
}
}
}
}
}