Skip to content

Commit 490558f

Browse files
Merge pull request #93 from riccardo-salamanna/master
added provisions for cpu, memory, and i/o shares
2 parents 33419b6 + a092f44 commit 490558f

File tree

5 files changed

+76
-13
lines changed

5 files changed

+76
-13
lines changed

main.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,13 @@ resource "vsphere_virtual_machine" "vm" {
7979
cpu_hot_add_enabled = var.cpu_hot_add_enabled
8080
cpu_hot_remove_enabled = var.cpu_hot_remove_enabled
8181
cpu_reservation = var.cpu_reservation
82+
cpu_share_level = var.cpu_share_level
83+
cpu_share_count = var.cpu_share_level == "custom" ? var.cpu_share_count : null
8284
memory_reservation = var.memory_reservation
8385
memory = var.ram_size
8486
memory_hot_add_enabled = var.memory_hot_add_enabled
87+
memory_share_level = var.memory_share_level
88+
memory_share_count = var.memory_share_level == "custom" ? var.memory_share_count : null
8589
guest_id = data.vsphere_virtual_machine.template.guest_id
8690
scsi_bus_sharing = var.scsi_bus_sharing
8791
scsi_type = var.scsi_type != "" ? var.scsi_type : data.vsphere_virtual_machine.template.scsi_type
@@ -122,6 +126,9 @@ resource "vsphere_virtual_machine" "vm" {
122126
eagerly_scrub = data.vsphere_virtual_machine.template.disks[template_disks.key].eagerly_scrub
123127
datastore_id = var.disk_datastore != "" ? data.vsphere_datastore.disk_datastore[0].id : null
124128
storage_policy_id = length(var.template_storage_policy_id) > 0 ? var.template_storage_policy_id[template_disks.key] : null
129+
io_reservation = length(var.io_reservation) > 0 ? var.io_reservation[template_disks.key] : null
130+
io_share_level = length(var.io_share_level) > 0 ? var.io_share_level[template_disks.key] : "normal"
131+
io_share_count = length(var.io_share_level) > 0 && var.io_share_level[template_disks.key] == "custom" ? var.io_share_count[template_disks.key] : null
125132
}
126133
}
127134
// Additional disks defined by Terraform config
@@ -156,6 +163,9 @@ resource "vsphere_virtual_machine" "vm" {
156163
eagerly_scrub = lookup(terraform_disks.value, "eagerly_scrub", "false")
157164
datastore_id = lookup(terraform_disks.value, "datastore_id", null)
158165
storage_policy_id = lookup(terraform_disks.value, "storage_policy_id", null)
166+
io_reservation = lookup(terraform_disks.value, "io_reservation", null)
167+
io_share_level = lookup(terraform_disks.value, "io_share_level", "normal")
168+
io_share_count = lookup(terraform_disks.value, "io_share_level", null) == "custom" ? lookup(terraform_disks.value, "io_share_count") : null
159169
}
160170
}
161171
clone {

tests/sanity/main.tf

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,26 @@ variable "env" {
2121

2222
variable "vm" {
2323
type = map(object({
24-
vmname = string
25-
vmtemp = string
26-
dc = string
27-
vmrp = string
28-
vmfolder = string
29-
datastore = string
30-
is_windows_image = bool
31-
tags = map(string)
32-
instances = number
33-
network = map(list(string))
34-
vmgateway = string
35-
dns_servers = list(string)
36-
data_disk = map(map(string))
24+
vmname = string
25+
vmtemp = string
26+
dc = string
27+
vmrp = string
28+
vmfolder = string
29+
datastore = string
30+
is_windows_image = bool
31+
tags = map(string)
32+
instances = number
33+
network = map(list(string))
34+
vmgateway = string
35+
dns_servers = list(string)
36+
data_disk = map(map(string))
37+
cpu_share_level = string
38+
cpu_share_count = number
39+
memory_share_level = string
40+
memory_share_count = number
41+
io_reservation = list(number)
42+
io_share_level = list(string)
43+
io_share_count = list(number)
3744
}))
3845
}
3946

@@ -54,6 +61,12 @@ module "example-server-basic" {
5461
dc = each.value.dc
5562
datastore = each.value.datastore
5663
data_disk = each.value.data_disk
64+
cpu_share_level = each.value.cpu_share_level
65+
# cpu_share_count = each.value.cpu_share_level == "custom" ? each.value.cpu_share_count : null
66+
# memory_share_level = each.value.memory_share_level
67+
# memory_share_count = each.value.memory_share_level == "custom" ? each.value.memory_share_count : null
68+
# io_share_level = each.value.io_share_level
69+
# io_share_count = each.value.io_share_level == "custom" ? each.value.io_share_count : null
5770
}
5871

5972
output "DC_ID" {

tests/sanity/plan.sh

100644100755
File mode changed.

tests/smoke/plan.sh

100644100755
File mode changed.

variables.tf

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,23 @@ variable "disk_datastore" {
5151
type = string
5252
default = ""
5353
}
54+
variable "io_reservation" {
55+
description = "The I/O reservation (guarantee) that this disk has, in IOPS. The default is no reservation."
56+
type = list(number)
57+
default = []
58+
}
59+
60+
variable "io_share_level" {
61+
description = "The share allocation level for this disk. Can be one of low, normal, high, or custom. Default: normal."
62+
type = list(string)
63+
default = ["normal"]
64+
}
65+
66+
variable "io_share_count" {
67+
description = "The share count for this disk when the share level is custom."
68+
type = list(number)
69+
default = []
70+
}
5471

5572
variable "template_storage_policy_id" {
5673
description = "List of UUIDs of the storage policy to assign to the template disk."
@@ -126,6 +143,18 @@ variable "cpu_reservation" {
126143
default = null
127144
}
128145

146+
variable "cpu_share_level" {
147+
description = "The allocation level for CPU resources. Can be one of high, low, normal, or custom. Default: custom."
148+
type = string
149+
default = "normal"
150+
}
151+
152+
variable "cpu_share_count" {
153+
description = "The number of CPU shares allocated to the virtual machine when the cpu_share_level is custom."
154+
type = number
155+
default = 4000
156+
}
157+
129158
variable "ram_size" {
130159
description = "VM RAM size in megabytes."
131160
default = 4096
@@ -241,6 +270,17 @@ variable "memory_reservation" {
241270
default = null
242271
}
243272

273+
variable "memory_share_level" {
274+
description = "The allocation level for memory resources. Can be one of high, low, normal, or custom"
275+
type = string
276+
default = "normal"
277+
}
278+
279+
variable "memory_share_count" {
280+
description = "(Optional) The number of memory shares allocated to the virtual machine when the memory_share_level is custom"
281+
type = number
282+
default = 81920
283+
}
244284

245285
#Linux Customization Variables
246286
variable "hw_clock_utc" {

0 commit comments

Comments
 (0)