Skip to content

Commit 321fcf8

Browse files
Merge pull request #39 from LennertMertens/feature/boolean-variables
Feature/boolean variables
2 parents cb8acdd + c1681d7 commit 321fcf8

File tree

8 files changed

+50
-43
lines changed

8 files changed

+50
-43
lines changed

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Terraform vSphere Module
22

3-
![Terraform Version](https://img.shields.io/badge/Terraform-0.12.6-green.svg) [![TF Registry](https://img.shields.io/badge/terraform-registry-blue.svg)](https://registry.terraform.io/modules/Terraform-VMWare-Modules/vm/vsphere/) [![Changelog](https://img.shields.io/badge/changelog-release-green.svg)](https://github.com/Terraform-VMWare-Modules/terraform-vsphere-vm/releases) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
3+
![Terraform Version](https://img.shields.io/badge/Terraform-0.12.6-green.svg) [![TF Registry](https://img.shields.io/badge/terraform-registry-blue.svg)](https://registry.terraform.io/modules/Terraform-VMWare-Modules/vm/vsphere/) [![Changelog](https://img.shields.io/badge/changelog-release-green.svg)](https://github.com/Terraform-VMWare-Modules/terraform-vsphere-vm/releases) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
44

55
For Virtual Machine Provisioning with (Linux/Windows) customization. Thanks to the new enhancements introduced in Terraform v0.12.6 this module include most of the advance features that are available in the resource `vsphere_virtual_machine`.
66

@@ -54,7 +54,7 @@ module "example-server-windowsvm" {
5454
source = "Terraform-VMWare-Modules/vm/vsphere"
5555
version = "X.X.X"
5656
vmtemp = "TemplateName"
57-
is_windows_image = "true"
57+
is_windows_image = true
5858
instances = 1
5959
vmname = "example-server-windows"
6060
vmrp = "esxi/Resources"
@@ -75,7 +75,7 @@ There are number of switches defined in the module, where you can use to enable
7575

7676
### Main Feature Switches
7777

78-
- You can use `is_windows_image = "true"` to set the customization type to Windows (By default it is set to Linux customization)
78+
- You can use `is_windows_image = true` to set the customization type to Windows (By default it is set to Linux customization)
7979
- You can use `data_disk_size_gb = [20,30]` to add additional data disks (Supported in both Linux and Windows deployment)
8080
- Above switch will create two additional disk of capacity 10 and 30gb for the VM.
8181
- You can include `thin_provisioned` switch to define disk type for each additional disk.
@@ -101,9 +101,9 @@ module "example-server-windowsvm-advanced" {
101101
ram_size = 2096
102102
cpu_reservation = 2000
103103
memory_reservation = 2000
104-
cpu_hot_add_enabled = "true"
105-
cpu_hot_remove_enabled = "true"
106-
memory_hot_add_enabled = "true"
104+
cpu_hot_add_enabled = true
105+
cpu_hot_remove_enabled = true
106+
memory_hot_add_enabled = true
107107
vmname = "AdvancedVM"
108108
vmdomain = "somedomain.com"
109109
network_cards = ["VM Network", "test-network"] #Assign multiple cards
@@ -114,7 +114,7 @@ module "example-server-windowsvm-advanced" {
114114
"test" = ["", "192.168.0.3"]
115115
}
116116
data_disk_size_gb = [10, 5] // Aditional Disk to be used
117-
thin_provisioned = ["true", "false"]
117+
thin_provisioned = [true, false]
118118
disk_label = ["tpl-disk-1"]
119119
data_disk_label = ["label1", "label2"]
120120
disk_datastore = "vsanDatastore" // This will store Template disk in the defined disk_datastore
@@ -129,12 +129,12 @@ module "example-server-windowsvm-advanced" {
129129
"terraform-test-category" = "terraform-test-tag"
130130
"terraform-test-category-02" = "terraform-test-tag-02"
131131
}
132-
enable_disk_uuid = "true"
133-
auto_logon = "true"
132+
enable_disk_uuid = true
133+
auto_logon = true
134134
run_once = ["command01", "command02"] // You can also run Powershell commands
135135
orgname = "Terraform-Module"
136136
workgroup = "Module-Test"
137-
is_windows_image = "true"
137+
is_windows_image = true
138138
firmware = "efi"
139139
local_adminpass = "Password@Strong"
140140
}

examples/linux/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ module "example-server-linuxvm-withdatadisk" {
4545
instances = 2
4646
cpu_number = 2
4747
ram_size = 2096
48-
cpu_hot_add_enabled = "true"
49-
cpu_hot_remove_enabled = "true"
50-
memory_hot_add_enabled = "true"
48+
cpu_hot_add_enabled = true
49+
cpu_hot_remove_enabled = true
50+
memory_hot_add_enabled = true
5151
vmname = "AdvancedVM"
5252
vmdomain = "somedomain.com"
5353
network_cards = ["VM Network", "test-network"]
@@ -64,7 +64,7 @@ module "example-server-linuxvm-withdatadisk" {
6464
data_disk_scsi_controller = [0, 1]
6565
disk_datastore = "vsanDatastore"
6666
data_disk_datastore = ["vsanDatastore", "nfsDatastore"]
67-
thin_provisioned = ["true", "false"]
67+
thin_provisioned = [true, false]
6868
vmdns = ["192.168.0.2", "192.168.0.1"]
6969
vmgateway = "192.168.0.1"
7070
network_type = ["vmxnet3", "vmxnet3"]

examples/linux/example-depend_on.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ module "example-server-linuxvm-advanced" {
2626
instances = 2
2727
cpu_number = 2
2828
ram_size = 2096
29-
cpu_hot_add_enabled = "true"
30-
cpu_hot_remove_enabled = "true"
31-
memory_hot_add_enabled = "true"
29+
cpu_hot_add_enabled = true
30+
cpu_hot_remove_enabled = true
31+
memory_hot_add_enabled = true
3232
vmname = "AdvancedVM"
3333
vmdomain = "somedomain.com"
3434
network_cards = ["VM Network", "test-network"]
@@ -45,7 +45,7 @@ module "example-server-linuxvm-advanced" {
4545
disk_datastore = "vsanDatastore"
4646
data_disk_datastore = ["vsanDatastore", "nfsDatastore"]
4747
data_disk_size_gb = [10, 5] // Aditional Disks to be used
48-
thin_provisioned = ["true", "false"]
48+
thin_provisioned = [true, false]
4949
vmdns = ["192.168.0.2", "192.168.0.1"]
5050
vmgateway = "192.168.0.1"
5151
network_type = ["vmxnet3", "vmxnet3"]

examples/linux/main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ module "example-server-linuxvm-advanced" {
2525
instances = 2
2626
cpu_number = 2
2727
ram_size = 2096
28-
cpu_hot_add_enabled = "true"
29-
cpu_hot_remove_enabled = "true"
30-
memory_hot_add_enabled = "true"
28+
cpu_hot_add_enabled = true
29+
cpu_hot_remove_enabled = true
30+
memory_hot_add_enabled = true
3131
vmname = "AdvancedVM"
3232
vmdomain = "somedomain.com"
3333
network_cards = ["VM Network", "test-network"]
@@ -44,7 +44,7 @@ module "example-server-linuxvm-advanced" {
4444
disk_datastore = "vsanDatastore"
4545
data_disk_datastore = ["vsanDatastore", "nfsDatastore"]
4646
data_disk_size_gb = [10, 5] // Aditional Disks to be used
47-
thin_provisioned = ["true", "false"]
47+
thin_provisioned = [true, false]
4848
vmdns = ["192.168.0.2", "192.168.0.1"]
4949
vmgateway = "192.168.0.1"
5050
network_type = ["vmxnet3", "vmxnet3"]

examples/windows/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ module "example-server-windowsvm-advanced" {
4141
instances = 2
4242
cpu_number = 2
4343
ram_size = 2096
44-
cpu_hot_add_enabled = "true"
45-
cpu_hot_remove_enabled = "true"
46-
memory_hot_add_enabled = "true"
44+
cpu_hot_add_enabled = true
45+
cpu_hot_remove_enabled = true
46+
memory_hot_add_enabled = true
4747
vmname = "AdvancedVM"
4848
vmdomain = "somedomain.com"
4949
network_cards = ["VM Network", "test-netwrok"]
@@ -60,20 +60,20 @@ module "example-server-windowsvm-advanced" {
6060
data_disk_scsi_controller = [0, 1]
6161
disk_datastore = "vsanDatastore"
6262
data_disk_datastore = ["vsanDatastore", "nfsDatastore"]
63-
thin_provisioned = ["true", "false"]
63+
thin_provisioned = [true, false]
6464
vmdns = ["192.168.0.2", "192.168.0.1"]
6565
vmgateway = "192.168.0.1"
6666
network_type = ["vmxnet3", "vmxnet3"]
6767
tags = {
6868
"terraform-test-category" = "terraform-test-tag"
6969
"terraform-test-category-02" = "terraform-test-tag-02"
7070
}
71-
enable_disk_uuid = "true"
72-
auto_logon = "true"
71+
enable_disk_uuid = true
72+
auto_logon = true
7373
run_once = ["mkdir c:\\admin", "echo runonce-test >> c:\\admin\\logs.txt", "powershell.exe \"New-Item C:\\test.txt\""]
7474
orgname = "Terraform-Module"
7575
workgroup = "Module-Test"
76-
is_windows_image = "true"
76+
is_windows_image = true
7777
firmware = "efi"
7878
local_adminpass = "Password@Strong"
7979
}

examples/windows/main.tf

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module "example-server-windowsvm-withdatadisk" {
33
source = "Terraform-VMWare-Modules/vm/vsphere"
44
version = "Latest X.X.X"
55
vmtemp = "TemplateName"
6-
is_windows_image = "true"
6+
is_windows_image = true
77
instances = 1
88
vmname = "example-server-windows"
99
vmrp = "esxi/Resources"
@@ -19,7 +19,7 @@ module "example-server-windowsvm-withdatadisk" {
1919
source = "Terraform-VMWare-Modules/vm/vsphere"
2020
version = "1.1.0"
2121
vmtemp = "TemplateName"
22-
is_windows_image = "true"
22+
is_windows_image = true
2323
windomain = "Development.com"
2424
domain_admin_user = "Domain admin user"
2525
domain_admin_password = "SomePassword"
@@ -45,9 +45,9 @@ module "example-server-windowsvm-advanced" {
4545
instances = 2
4646
cpu_number = 2
4747
ram_size = 2096
48-
cpu_hot_add_enabled = "true"
49-
cpu_hot_remove_enabled = "true"
50-
memory_hot_add_enabled = "true"
48+
cpu_hot_add_enabled = true
49+
cpu_hot_remove_enabled = true
50+
memory_hot_add_enabled = true
5151
vmname = "AdvancedVM"
5252
vmdomain = "somedomain.com"
5353
network_cards = ["VM Network", "test-network"]
@@ -64,20 +64,20 @@ module "example-server-windowsvm-advanced" {
6464
disk_datastore = "vsanDatastore"
6565
data_disk_datastore = ["vsanDatastore", "nfsDatastore"]
6666
data_disk_size_gb = [10, 5] // Aditional Disks to be used
67-
thin_provisioned = ["true", "false"]
67+
thin_provisioned = [true, false]
6868
vmdns = ["192.168.0.2", "192.168.0.1"]
6969
vmgateway = "192.168.0.1"
7070
network_type = ["vmxnet3", "vmxnet3"]
7171
tags = {
7272
"terraform-test-category" = "terraform-test-tag"
7373
"terraform-test-category-02" = "terraform-test-tag-02"
7474
}
75-
enable_disk_uuid = "true"
76-
auto_logon = "true"
75+
enable_disk_uuid = true
76+
auto_logon = true
7777
run_once = ["command01", "powershell.exe \"New-Item C:\\test.txt\""] // You can also run Powershell commands
7878
orgname = "Terraform-Module"
7979
workgroup = "Module-Test"
80-
is_windows_image = "true"
80+
is_windows_image = true
8181
firmware = "efi"
8282
local_adminpass = "Password123"
8383
}

main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ locals {
6262

6363
// Cloning a Linux VM from a given template. Note: This is the default option!!
6464
resource "vsphere_virtual_machine" "Linux" {
65-
count = var.is_windows_image != "true" ? var.instances : 0
65+
count = var.is_windows_image ? 0 : var.instances
6666
depends_on = [var.vm_depends_on]
6767
name = "%{if var.vmnameliteral != ""}${var.vmnameliteral}%{else}${var.vmname}${count.index + 1}${var.vmnamesuffix}%{endif}"
6868

@@ -158,7 +158,7 @@ resource "vsphere_virtual_machine" "Linux" {
158158
}
159159

160160
resource "vsphere_virtual_machine" "Windows" {
161-
count = var.is_windows_image == "true" ? var.instances : 0
161+
count = var.is_windows_image ? var.instances : 0
162162
depends_on = [var.vm_depends_on]
163163
name = "%{if var.vmnameliteral != ""}${var.vmnameliteral}%{else}${var.vmname}${count.index + 1}${var.vmnamesuffix}%{endif}"
164164

variables.tf

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,19 @@ variable "num_cores_per_socket" {
149149

150150
variable "cpu_hot_add_enabled" {
151151
description = "Allow CPUs to be added to this virtual machine while it is running."
152+
type = bool
152153
default = null
153154
}
154155

155156
variable "cpu_hot_remove_enabled" {
156157
description = "Allow CPUs to be removed to this virtual machine while it is running."
158+
type = bool
157159
default = null
158160
}
159161

160162
variable "memory_hot_add_enabled" {
161163
description = "Allow memory to be added to this virtual machine while it is running."
164+
type = bool
162165
default = null
163166
}
164167

@@ -247,6 +250,7 @@ variable "eagerly_scrub" {
247250

248251
variable "enable_disk_uuid" {
249252
description = "Expose the UUIDs of attached virtual disks to the virtual machine, allowing access to them in the guest."
253+
type = bool
250254
default = null
251255
}
252256

@@ -259,6 +263,7 @@ variable "network_type" {
259263
#Linux Customization Variables
260264
variable "hw_clock_utc" {
261265
description = "Tells the operating system that the hardware clock is set to UTC"
266+
type = bool
262267
default = true
263268
}
264269

@@ -271,6 +276,7 @@ variable "vmdomain" {
271276
#Windows Customization Variables
272277
variable "is_windows_image" {
273278
description = "Boolean flag to notify when the custom image is windows based."
279+
type = bool
274280
default = false
275281
}
276282

@@ -306,6 +312,7 @@ variable "orgname" {
306312

307313
variable "auto_logon" {
308314
description = " Specifies whether or not the VM automatically logs on as Administrator. Default: false"
315+
type = bool
309316
default = null
310317
}
311318

@@ -337,20 +344,20 @@ variable "full_name" {
337344

338345
variable "wait_for_guest_net_routable" {
339346
description = "Controls whether or not the guest network waiter waits for a routable address. When false, the waiter does not wait for a default gateway, nor are IP addresses checked against any discovered default gateways as part of its success criteria. This property is ignored if the wait_for_guest_ip_timeout waiter is used."
340-
default = true
341347
type = bool
348+
default = true
342349
}
343350

344351
variable "wait_for_guest_ip_timeout" {
345352
description = "The amount of time, in minutes, to wait for an available guest IP address on this virtual machine. This should only be used if your version of VMware Tools does not allow the wait_for_guest_net_timeout waiter to be used. A value less than 1 disables the waiter."
346-
default = 0
347353
type = number
354+
default = 0
348355
}
349356

350357
variable "wait_for_guest_net_timeout" {
351358
description = "The amount of time, in minutes, to wait for an available IP address on this virtual machine's NICs. Older versions of VMware Tools do not populate this property. In those cases, this waiter can be disabled and the wait_for_guest_ip_timeout waiter can be used instead. A value less than 1 disables the waiter."
352-
default = 5
353359
type = number
360+
default = 5
354361
}
355362

356363
variable "vm_depends_on" {

0 commit comments

Comments
 (0)