Skip to content

Commit

Permalink
Merge pull request #93 from riccardo-salamanna/master
Browse files Browse the repository at this point in the history
added provisions for cpu, memory, and i/o shares
  • Loading branch information
Arman-Keyoumarsi authored Jul 6, 2021
2 parents 33419b6 + a092f44 commit 490558f
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 13 deletions.
10 changes: 10 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,13 @@ resource "vsphere_virtual_machine" "vm" {
cpu_hot_add_enabled = var.cpu_hot_add_enabled
cpu_hot_remove_enabled = var.cpu_hot_remove_enabled
cpu_reservation = var.cpu_reservation
cpu_share_level = var.cpu_share_level
cpu_share_count = var.cpu_share_level == "custom" ? var.cpu_share_count : null
memory_reservation = var.memory_reservation
memory = var.ram_size
memory_hot_add_enabled = var.memory_hot_add_enabled
memory_share_level = var.memory_share_level
memory_share_count = var.memory_share_level == "custom" ? var.memory_share_count : null
guest_id = data.vsphere_virtual_machine.template.guest_id
scsi_bus_sharing = var.scsi_bus_sharing
scsi_type = var.scsi_type != "" ? var.scsi_type : data.vsphere_virtual_machine.template.scsi_type
Expand Down Expand Up @@ -122,6 +126,9 @@ resource "vsphere_virtual_machine" "vm" {
eagerly_scrub = data.vsphere_virtual_machine.template.disks[template_disks.key].eagerly_scrub
datastore_id = var.disk_datastore != "" ? data.vsphere_datastore.disk_datastore[0].id : null
storage_policy_id = length(var.template_storage_policy_id) > 0 ? var.template_storage_policy_id[template_disks.key] : null
io_reservation = length(var.io_reservation) > 0 ? var.io_reservation[template_disks.key] : null
io_share_level = length(var.io_share_level) > 0 ? var.io_share_level[template_disks.key] : "normal"
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
}
}
// Additional disks defined by Terraform config
Expand Down Expand Up @@ -156,6 +163,9 @@ resource "vsphere_virtual_machine" "vm" {
eagerly_scrub = lookup(terraform_disks.value, "eagerly_scrub", "false")
datastore_id = lookup(terraform_disks.value, "datastore_id", null)
storage_policy_id = lookup(terraform_disks.value, "storage_policy_id", null)
io_reservation = lookup(terraform_disks.value, "io_reservation", null)
io_share_level = lookup(terraform_disks.value, "io_share_level", "normal")
io_share_count = lookup(terraform_disks.value, "io_share_level", null) == "custom" ? lookup(terraform_disks.value, "io_share_count") : null
}
}
clone {
Expand Down
39 changes: 26 additions & 13 deletions tests/sanity/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,26 @@ variable "env" {

variable "vm" {
type = map(object({
vmname = string
vmtemp = string
dc = string
vmrp = string
vmfolder = string
datastore = string
is_windows_image = bool
tags = map(string)
instances = number
network = map(list(string))
vmgateway = string
dns_servers = list(string)
data_disk = map(map(string))
vmname = string
vmtemp = string
dc = string
vmrp = string
vmfolder = string
datastore = string
is_windows_image = bool
tags = map(string)
instances = number
network = map(list(string))
vmgateway = string
dns_servers = list(string)
data_disk = map(map(string))
cpu_share_level = string
cpu_share_count = number
memory_share_level = string
memory_share_count = number
io_reservation = list(number)
io_share_level = list(string)
io_share_count = list(number)
}))
}

Expand All @@ -54,6 +61,12 @@ module "example-server-basic" {
dc = each.value.dc
datastore = each.value.datastore
data_disk = each.value.data_disk
cpu_share_level = each.value.cpu_share_level
# cpu_share_count = each.value.cpu_share_level == "custom" ? each.value.cpu_share_count : null
# memory_share_level = each.value.memory_share_level
# memory_share_count = each.value.memory_share_level == "custom" ? each.value.memory_share_count : null
# io_share_level = each.value.io_share_level
# io_share_count = each.value.io_share_level == "custom" ? each.value.io_share_count : null
}

output "DC_ID" {
Expand Down
Empty file modified tests/sanity/plan.sh
100644 → 100755
Empty file.
Empty file modified tests/smoke/plan.sh
100644 → 100755
Empty file.
40 changes: 40 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,23 @@ variable "disk_datastore" {
type = string
default = ""
}
variable "io_reservation" {
description = "The I/O reservation (guarantee) that this disk has, in IOPS. The default is no reservation."
type = list(number)
default = []
}

variable "io_share_level" {
description = "The share allocation level for this disk. Can be one of low, normal, high, or custom. Default: normal."
type = list(string)
default = ["normal"]
}

variable "io_share_count" {
description = "The share count for this disk when the share level is custom."
type = list(number)
default = []
}

variable "template_storage_policy_id" {
description = "List of UUIDs of the storage policy to assign to the template disk."
Expand Down Expand Up @@ -126,6 +143,18 @@ variable "cpu_reservation" {
default = null
}

variable "cpu_share_level" {
description = "The allocation level for CPU resources. Can be one of high, low, normal, or custom. Default: custom."
type = string
default = "normal"
}

variable "cpu_share_count" {
description = "The number of CPU shares allocated to the virtual machine when the cpu_share_level is custom."
type = number
default = 4000
}

variable "ram_size" {
description = "VM RAM size in megabytes."
default = 4096
Expand Down Expand Up @@ -241,6 +270,17 @@ variable "memory_reservation" {
default = null
}

variable "memory_share_level" {
description = "The allocation level for memory resources. Can be one of high, low, normal, or custom"
type = string
default = "normal"
}

variable "memory_share_count" {
description = "(Optional) The number of memory shares allocated to the virtual machine when the memory_share_level is custom"
type = number
default = 81920
}

#Linux Customization Variables
variable "hw_clock_utc" {
Expand Down

0 comments on commit 490558f

Please sign in to comment.