-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
132 lines (113 loc) · 5.04 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
terraform {
required_version = "~> 1.2"
required_providers {
vcd = {
source = "vmware/vcd"
version = "~> 3.8"
}
}
}
data "vcd_vdc_group" "vdc_group" {
org = var.vdc_org_name
name = var.vdc_group_name
}
data "vcd_nsxt_edgegateway" "edge_gateway" {
org = var.vdc_org_name
owner_id = data.vcd_vdc_group.vdc_group.id
name = var.vdc_edge_name
}
locals {
network_data = { for net in var.org_networks : net.name => net }
}
data "vcd_network_routed_v2" "segment_routed" {
for_each = { for name, net in local.network_data : name => net if net.type == "routed" }
org = var.vdc_org_name
edge_gateway_id = data.vcd_nsxt_edgegateway.edge_gateway.id
name = each.value.name
}
data "vcd_network_isolated_v2" "segment_isolated" {
for_each = { for name, net in local.network_data : name => net if net.type == "isolated" }
org = var.vdc_org_name
owner_id = data.vcd_vdc_group.vdc_group.id
name = each.value.name
}
data "vcd_vm_sizing_policy" "sizing_policy" {
name = var.vm_sizing_policy_name
}
data "vcd_catalog" "catalog" {
org = var.catalog_org_name
name = var.catalog_name
}
data "vcd_catalog_vapp_template" "template" {
org = var.vdc_org_name
catalog_id = data.vcd_catalog.catalog.id
name = var.catalog_template_name
}
resource "vcd_vm" "vm" {
for_each = { for i in range(var.vm_count) : i => i }
org = var.vdc_org_name
vdc = var.vdc_name
name = var.vm_name_format != "" ? format(var.vm_name_format, var.vm_name[each.key % length(var.vm_name)], each.key + 1) : var.vm_name[each.key % length(var.vm_name)]
computer_name = var.computer_name_format != "" ? format(var.computer_name_format, var.computer_name[each.key % length(var.computer_name)], each.key + 1) : var.computer_name[each.key % length(var.computer_name)]
vapp_template_id = data.vcd_catalog_vapp_template.template.id
cpu_hot_add_enabled = var.vm_cpu_hot_add_enabled
memory_hot_add_enabled = var.vm_memory_hot_add_enabled
sizing_policy_id = data.vcd_vm_sizing_policy.sizing_policy.id
cpus = var.vm_min_cpu
dynamic "metadata_entry" {
for_each = var.vm_metadata_entries
content {
key = metadata_entry.value.key
value = metadata_entry.value.value
type = metadata_entry.value.type
user_access = metadata_entry.value.user_access
is_system = metadata_entry.value.is_system
}
}
dynamic "disk" {
for_each = can(var.vm_disks) ? slice(var.vm_disks, each.key * var.disks_per_vm, (each.key + 1) * var.disks_per_vm) : []
content {
name = can(disk.value) ? disk.value.name : null
bus_number = can(disk.value) ? disk.value.bus_number : null
unit_number = can(disk.value) ? disk.value.unit_number : null
}
}
dynamic "network" {
for_each = var.network_interfaces
content {
type = network.value.type
name = network.value.name
ip_allocation_mode = network.value.ip_allocation_mode
ip = network.value.ip_allocation_mode == "MANUAL" ? element(var.vm_ips, each.key * var.vm_ips_index_multiplier + network.key) : ""
is_primary = network.value.is_primary
}
}
dynamic "override_template_disk" {
for_each = var.override_template_disks
content {
bus_type = override_template_disk.value.bus_type
size_in_mb = override_template_disk.value.size_in_mb
bus_number = override_template_disk.value.bus_number
unit_number = override_template_disk.value.unit_number
iops = override_template_disk.value.iops
storage_profile = override_template_disk.value.storage_profile
}
}
customization {
force = var.vm_customization_force
enabled = var.vm_customization_enabled
change_sid = var.vm_customization_change_sid
allow_local_admin_password = var.vm_customization_allow_local_admin_password
must_change_password_on_first_login = var.vm_customization_must_change_password_on_first_login
auto_generate_password = var.vm_customization_auto_generate_password
admin_password = var.vm_customization_admin_password
number_of_auto_logons = var.vm_customization_number_of_auto_logons
join_domain = var.vm_customization_join_domain
join_org_domain = var.vm_customization_join_org_domain
join_domain_name = var.vm_customization_join_domain_name
join_domain_user = var.vm_customization_join_domain_user
join_domain_password = var.vm_customization_join_domain_password
join_domain_account_ou = var.vm_customization_join_domain_account_ou
initscript = var.vm_customization_initscript
}
}