Skip to content

Commit 455275a

Browse files
Merge pull request #46 from LennertMertens/feature/override-data-disk-size
Feature/override disk size
2 parents 0722e0b + 08088a2 commit 455275a

File tree

4 files changed

+97
-3
lines changed

4 files changed

+97
-3
lines changed

examples/linux/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,46 @@ module "example-server-linuxvm-withdatadisk" {
7575
}
7676
```
7777

78+
### Example of template disk size configuration
79+
80+
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.
81+
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.
82+
83+
```hcl
84+
module "example-server-linuxvm-override-template-size" {
85+
source = "Terraform-VMWare-Modules/vm/vsphere"
86+
version = "Latest X.X.X"
87+
dc = "Datacenter"
88+
vmrp = "cluster/Resources"
89+
vmfolder = "Cattle"
90+
ds_cluster = "Datastore Cluster"
91+
vmtemp = "TemplateName"
92+
instances = 2
93+
cpu_number = 2
94+
ram_size = 2096
95+
vmname = "AdvancedVM"
96+
vmdomain = "somedomain.com"
97+
network_cards = ["VM Network"]
98+
ipv4submask = ["24"]
99+
ipv4 = {
100+
"VM Network" = ["192.168.0.4"]
101+
}
102+
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)
103+
disk_label = ["tpl-disk-1"]
104+
data_disk_size_gb = [10] // Aditional Disk to be used
105+
data_disk_label = ["label1"]
106+
disk_datastore = "vsanDatastore"
107+
data_disk_datastore = ["vsanDatastore"]
108+
thin_provisioned = [true]
109+
vmdns = ["192.168.0.2"]
110+
vmgateway = "192.168.0.1"
111+
network_type = ["vmxnet3"]
112+
tags = {
113+
"terraform-test-category" = "terraform-test-tag"
114+
}
115+
}
116+
```
117+
78118
## Authors
79119

80120
Originally created by [Arman Keyoumarsi](https://github.com/Arman-Keyoumarsi)

examples/windows/README.md

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module "example-server-windowsvm-withdatadisk" {
3131

3232
```hcl
3333
module "example-server-windowsvm-advanced" {
34-
source = "Terraform-VMWare-Modules/vm/vsphere"
34+
source = "Terraform-VMWare-Modules/vm/vsphere"
3535
version = "Latest X.X.X"
3636
dc = "Datacenter"
3737
vmrp = "cluster/Resources"
@@ -79,6 +79,54 @@ module "example-server-windowsvm-advanced" {
7979
}
8080
```
8181

82+
### Example of template disk size configuration
83+
84+
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.
85+
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.
86+
87+
```hcl
88+
module "example-server-windowsvm-override-template-size" {
89+
source = "Terraform-VMWare-Modules/vm/vsphere"
90+
version = "Latest X.X.X"
91+
dc = "Datacenter"
92+
vmrp = "cluster/Resources"
93+
vmfolder = "Cattle"
94+
ds_cluster = "Datastore Cluster"
95+
vmtemp = "TemplateName"
96+
instances = 2
97+
cpu_number = 2
98+
ram_size = 2096
99+
vmname = "AdvancedVM"
100+
vmdomain = "somedomain.com"
101+
network_cards = ["VM Network"]
102+
ipv4submask = ["24"]
103+
ipv4 = {
104+
"VM Network" = ["192.168.0.4"]
105+
}
106+
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)
107+
disk_label = ["tpl-disk-1"]
108+
data_disk_size_gb = [10] // Aditional Disk to be used
109+
data_disk_label = ["label1"]
110+
disk_datastore = "vsanDatastore"
111+
data_disk_datastore = ["vsanDatastore"]
112+
thin_provisioned = [true]
113+
vmdns = ["192.168.0.2"]
114+
vmgateway = "192.168.0.1"
115+
network_type = ["vmxnet3"]
116+
tags = {
117+
"terraform-test-category" = "terraform-test-tag"
118+
}
119+
enable_disk_uuid = true
120+
auto_logon = true
121+
run_once = ["mkdir c:\\admin", "echo runonce-test >> c:\\admin\\logs.txt", "powershell.exe \"New-Item C:\\test.txt\""]
122+
orgname = "Terraform-Module"
123+
workgroup = "Module-Test"
124+
is_windows_image = true
125+
firmware = "efi"
126+
local_adminpass = "Password@Strong"
127+
}
128+
```
129+
82130
## Authors
83131

84132
Originally created by [Arman Keyoumarsi](https://github.com/Arman-Keyoumarsi)

main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ resource "vsphere_virtual_machine" "Linux" {
111111
iterator = template_disks
112112
content {
113113
label = length(var.disk_label) > 0 ? var.disk_label[template_disks.key] : "disk${template_disks.key}"
114-
size = data.vsphere_virtual_machine.template.disks[template_disks.key].size
114+
size = var.disk_size_gb != null ? var.disk_size_gb[template_disks.key] : data.vsphere_virtual_machine.template.disks[template_disks.key].size
115115
unit_number = var.scsi_controller != null ? var.scsi_controller * 15 + template_disks.key : template_disks.key
116116
thin_provisioned = data.vsphere_virtual_machine.template.disks[template_disks.key].thin_provisioned
117117
eagerly_scrub = data.vsphere_virtual_machine.template.disks[template_disks.key].eagerly_scrub
@@ -221,7 +221,7 @@ resource "vsphere_virtual_machine" "Windows" {
221221
iterator = template_disks
222222
content {
223223
label = length(var.disk_label) > 0 ? var.disk_label[template_disks.key] : "disk${template_disks.key}"
224-
size = data.vsphere_virtual_machine.template.disks[template_disks.key].size
224+
size = var.disk_size_gb != null ? var.disk_size_gb[template_disks.key] : data.vsphere_virtual_machine.template.disks[template_disks.key].size
225225
unit_number = var.scsi_controller != null ? var.scsi_controller * 15 + template_disks.key : template_disks.key
226226
thin_provisioned = data.vsphere_virtual_machine.template.disks[template_disks.key].thin_provisioned
227227
eagerly_scrub = data.vsphere_virtual_machine.template.disks[template_disks.key].eagerly_scrub

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ variable "data_disk_size_gb" {
188188
default = []
189189
}
190190

191+
variable "disk_size_gb" {
192+
description = "List of disk sizes to override template disk size."
193+
type = list
194+
default = null
195+
}
196+
191197
variable "disk_datastore" {
192198
description = "Define where the OS disk should be stored."
193199
type = string

0 commit comments

Comments
 (0)