Skip to content

Commit

Permalink
Merge pull request #46 from LennertMertens/feature/override-data-disk…
Browse files Browse the repository at this point in the history
…-size

Feature/override disk size
  • Loading branch information
Arman-Keyoumarsi authored Oct 18, 2020
2 parents 0722e0b + 08088a2 commit 455275a
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 3 deletions.
40 changes: 40 additions & 0 deletions examples/linux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,46 @@ module "example-server-linuxvm-withdatadisk" {
}
```

### Example of template disk size configuration

Below example will deploy an instance of a virtual machine from a linux template. The virtual machine makes use of a template that is 16GB in size originally but is expanded to 32GB.
To override the disks configured in the virtual machine template add the `disk_size_gb` variable (list), and configure the disk sizes as integers to match the templates amount of disks.

```hcl
module "example-server-linuxvm-override-template-size" {
source = "Terraform-VMWare-Modules/vm/vsphere"
version = "Latest X.X.X"
dc = "Datacenter"
vmrp = "cluster/Resources"
vmfolder = "Cattle"
ds_cluster = "Datastore Cluster"
vmtemp = "TemplateName"
instances = 2
cpu_number = 2
ram_size = 2096
vmname = "AdvancedVM"
vmdomain = "somedomain.com"
network_cards = ["VM Network"]
ipv4submask = ["24"]
ipv4 = {
"VM Network" = ["192.168.0.4"]
}
disk_size_gb = [32] // Value to override the template disk size (add x amount of values to match the amount of disks in the template)
disk_label = ["tpl-disk-1"]
data_disk_size_gb = [10] // Aditional Disk to be used
data_disk_label = ["label1"]
disk_datastore = "vsanDatastore"
data_disk_datastore = ["vsanDatastore"]
thin_provisioned = [true]
vmdns = ["192.168.0.2"]
vmgateway = "192.168.0.1"
network_type = ["vmxnet3"]
tags = {
"terraform-test-category" = "terraform-test-tag"
}
}
```

## Authors

Originally created by [Arman Keyoumarsi](https://github.com/Arman-Keyoumarsi)
Expand Down
50 changes: 49 additions & 1 deletion examples/windows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module "example-server-windowsvm-withdatadisk" {

```hcl
module "example-server-windowsvm-advanced" {
source = "Terraform-VMWare-Modules/vm/vsphere"
source = "Terraform-VMWare-Modules/vm/vsphere"
version = "Latest X.X.X"
dc = "Datacenter"
vmrp = "cluster/Resources"
Expand Down Expand Up @@ -79,6 +79,54 @@ module "example-server-windowsvm-advanced" {
}
```

### Example of template disk size configuration

Below example will deploy an instance of a virtual machine from a Windows template. The virtual machine makes use of a template that is 16GB in size originally but is expanded to 32GB.
To override the disks configured in the virtual machine template add the `disk_size_gb` variable (list), and configure the disk sizes as integers to match the templates amount of disks.

```hcl
module "example-server-windowsvm-override-template-size" {
source = "Terraform-VMWare-Modules/vm/vsphere"
version = "Latest X.X.X"
dc = "Datacenter"
vmrp = "cluster/Resources"
vmfolder = "Cattle"
ds_cluster = "Datastore Cluster"
vmtemp = "TemplateName"
instances = 2
cpu_number = 2
ram_size = 2096
vmname = "AdvancedVM"
vmdomain = "somedomain.com"
network_cards = ["VM Network"]
ipv4submask = ["24"]
ipv4 = {
"VM Network" = ["192.168.0.4"]
}
disk_size_gb = [32] // Value to override the template disk size (add x amount of values to match the amount of disks in the template)
disk_label = ["tpl-disk-1"]
data_disk_size_gb = [10] // Aditional Disk to be used
data_disk_label = ["label1"]
disk_datastore = "vsanDatastore"
data_disk_datastore = ["vsanDatastore"]
thin_provisioned = [true]
vmdns = ["192.168.0.2"]
vmgateway = "192.168.0.1"
network_type = ["vmxnet3"]
tags = {
"terraform-test-category" = "terraform-test-tag"
}
enable_disk_uuid = true
auto_logon = true
run_once = ["mkdir c:\\admin", "echo runonce-test >> c:\\admin\\logs.txt", "powershell.exe \"New-Item C:\\test.txt\""]
orgname = "Terraform-Module"
workgroup = "Module-Test"
is_windows_image = true
firmware = "efi"
local_adminpass = "Password@Strong"
}
```

## Authors

Originally created by [Arman Keyoumarsi](https://github.com/Arman-Keyoumarsi)
Expand Down
4 changes: 2 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ resource "vsphere_virtual_machine" "Linux" {
iterator = template_disks
content {
label = length(var.disk_label) > 0 ? var.disk_label[template_disks.key] : "disk${template_disks.key}"
size = data.vsphere_virtual_machine.template.disks[template_disks.key].size
size = var.disk_size_gb != null ? var.disk_size_gb[template_disks.key] : data.vsphere_virtual_machine.template.disks[template_disks.key].size
unit_number = var.scsi_controller != null ? var.scsi_controller * 15 + template_disks.key : template_disks.key
thin_provisioned = data.vsphere_virtual_machine.template.disks[template_disks.key].thin_provisioned
eagerly_scrub = data.vsphere_virtual_machine.template.disks[template_disks.key].eagerly_scrub
Expand Down Expand Up @@ -221,7 +221,7 @@ resource "vsphere_virtual_machine" "Windows" {
iterator = template_disks
content {
label = length(var.disk_label) > 0 ? var.disk_label[template_disks.key] : "disk${template_disks.key}"
size = data.vsphere_virtual_machine.template.disks[template_disks.key].size
size = var.disk_size_gb != null ? var.disk_size_gb[template_disks.key] : data.vsphere_virtual_machine.template.disks[template_disks.key].size
unit_number = var.scsi_controller != null ? var.scsi_controller * 15 + template_disks.key : template_disks.key
thin_provisioned = data.vsphere_virtual_machine.template.disks[template_disks.key].thin_provisioned
eagerly_scrub = data.vsphere_virtual_machine.template.disks[template_disks.key].eagerly_scrub
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ variable "data_disk_size_gb" {
default = []
}

variable "disk_size_gb" {
description = "List of disk sizes to override template disk size."
type = list
default = null
}

variable "disk_datastore" {
description = "Define where the OS disk should be stored."
type = string
Expand Down

0 comments on commit 455275a

Please sign in to comment.