Skip to content

Commit c4f25cd

Browse files
Merge pull request #86 from Terraform-VMWare-Modules/rc/3.0.0
Refactored VM name to include static option
2 parents 150511b + 375dc71 commit c4f25cd

File tree

8 files changed

+56
-31
lines changed

8 files changed

+56
-31
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ module "example-server-windowsvm-advanced" {
8686
instances = 2
8787
vmname = "AdvancedVM"
8888
vmnameformat = "%03d" #To use three decimal with leading zero vmnames will be AdvancedVM001,AdvancedVM002
89-
vmdomain = "somedomain.com"
89+
domain = "somedomain.com"
9090
network = {
9191
"Name of the Port Group in vSphere" = ["10.13.113.2", "10.13.113.3"] # To use DHCP create Empty list ["",""]
9292
"Second Network Card" = ["", ""]
@@ -112,7 +112,7 @@ module "example-server-windowsvm-advanced" {
112112
scsi_bus_sharing = "physicalSharing" // The modes are physicalSharing, virtualSharing, and noSharing
113113
scsi_type = "lsilogic" // Other acceptable value "pvscsi"
114114
scsi_controller = 0 // This will assign OS disk to controller 0
115-
vmdns = ["192.168.0.2", "192.168.0.1"]
115+
dns_server_list = ["192.168.0.2", "192.168.0.1"]
116116
vmgateway = "192.168.0.1"
117117
enable_disk_uuid = true
118118
auto_logon = true

examples/example-Windows-data_disk.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module "example-server-windowsvm-advanced" {
1212
vmtemp = "TemplateName"
1313
instances = 2
1414
vmname = "AdvancedVM"
15-
vmdomain = "somedomain.com"
15+
domain = "somedomain.com"
1616
network = {
1717
"Name of the Port Group in vSphere" = ["10.13.113.2", "10.13.113.3"] # To use DHCP create Empty list ["",""]
1818
}
@@ -34,7 +34,7 @@ module "example-server-windowsvm-advanced" {
3434
scsi_bus_sharing = "physicalSharing" // The modes are physicalSharing, virtualSharing, and noSharing
3535
scsi_type = "lsilogic" // Other acceptable value "pvscsi"
3636
scsi_controller = 0 // This will assign OS disk to controller 0
37-
vmdns = ["192.168.0.2", "192.168.0.1"]
37+
dns_server_list = ["192.168.0.2", "192.168.0.1"]
3838
vmgateway = "192.168.0.1"
3939
enable_disk_uuid = true
4040
orgname = "Terraform-Module"

examples/example-linux-Network.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ module "example-server-linuxvm-advanced" {
99
vmtemp = "TemplateName"
1010
instances = 2
1111
vmname = "AdvancedVM"
12-
vmdomain = "somedomain.com"
12+
domain = "somedomain.com"
1313
ipv4submask = ["24", "8"]
1414
network = {
1515
"Network01" = ["10.13.113.2", "10.13.113.3"] # To use DHCP create Empty list ["",""]
1616
"Network02" = ["", ""] #Second Network will use the DHCP
1717
}
1818
disk_datastore = "vsanDatastore"
19-
vmdns = ["192.168.0.2", "192.168.0.1"]
19+
dns_server_list = ["192.168.0.2", "192.168.0.1"]
2020
vmgateway = "192.168.0.1"
2121
network_type = ["vmxnet3", "vmxnet3"]
2222
}

examples/example-linux-depend_on.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ module "example-server-linuxvm-advanced" {
3030
cpu_hot_remove_enabled = true
3131
memory_hot_add_enabled = true
3232
vmname = "AdvancedVM"
33-
vmdomain = "somedomain.com"
33+
domain = "somedomain.com"
3434
ipv4submask = ["24", "8"]
3535
network = {
3636
"Network01" = ["10.13.113.2", "10.13.113.3"] # To use DHCP create Empty list ["",""]
3737
"Network02" = ["", ""] #Second Network will use the DHCP
3838
}
39-
vmdns = ["192.168.0.2", "192.168.0.1"]
39+
dns_server_list = ["192.168.0.2", "192.168.0.1"]
4040
vmgateway = "192.168.0.1"
4141
network_type = ["vmxnet3", "vmxnet3"]
4242
tags = {

examples/example-vmname.tf

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
// Single VM deployment with literal name
22
module "example-server-single" {
3-
source = "Terraform-VMWare-Modules/vm/vsphere"
4-
version = "Latest X.X.X"
5-
vmtemp = "TemplateName"
6-
instances = 1
7-
vmname = "liternalvmname"
8-
vmrp = "esxi/Resources"
3+
source = "Terraform-VMWare-Modules/vm/vsphere"
4+
version = "Latest X.X.X"
5+
vmtemp = "TemplateName"
6+
staticvmname = "liternalvmname"
7+
vmrp = "esxi/Resources"
98
network = {
109
"Name of the Port Group in vSphere" = ["10.13.113.2"]
1110
}
@@ -14,25 +13,42 @@ module "example-server-single" {
1413
}
1514

1615
# Vmname Output -> liternalvmname
16+
//Sclae out Static VMs
17+
variable "name" {
18+
default = ["staticvmname", "staticvmname01"]
19+
}
1720

21+
module "example-server-single" {
22+
source = "Terraform-VMWare-Modules/vm/vsphere"
23+
for_each = toset(var.name)
24+
version = "Latest X.X.X"
25+
vmtemp = "TemplateName"
26+
staticvmname = "liternalvmname"
27+
vmrp = "esxi/Resources"
28+
network = {
29+
"Name of the Port Group in vSphere" = ["10.13.113.2"]
30+
}
31+
dc = "Datacenter"
32+
datastore = "Data Store name(use datastore_cluster for datastore cluster)"
33+
}
1834
// Example of multiple VM deployment with complex naming standard
1935
# Define Environment Variable to switch between Environments
2036
variable "env" {
2137
default = "dev"
2238
}
2339
module "example-server-multi" {
24-
source = "Terraform-VMWare-Modules/vm/vsphere"
25-
version = "Latest X.X.X"
26-
vmtemp = "TemplateName"
27-
instances = 2
28-
vmname = "advancevm"
40+
source = "Terraform-VMWare-Modules/vm/vsphere"
41+
version = "Latest X.X.X"
42+
vmtemp = "TemplateName"
43+
instances = 2
44+
vmname = "advancevm"
2945
vmnameformat = "%03d${var.env}"
30-
vmrp = "esxi/Resources"
46+
vmrp = "esxi/Resources"
3147
network = {
3248
"Name of the Port Group in vSphere" = ["10.13.113.2", ""]
3349
}
3450
dc = "Datacenter"
3551
datastore = "Data Store name(use datastore_cluster for datastore cluster)"
3652
}
3753

38-
# Vmname Output -> advancevm001dev, advancevm002dev
54+
# Vmname Output -> advancevm001dev, advancevm002dev

main.tf

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ locals {
5858
resource "vsphere_virtual_machine" "vm" {
5959
count = var.instances
6060
depends_on = [var.vm_depends_on]
61-
name = var.instances == 1 ? var.vmname : format("${var.vmname}${var.vmnameformat}", count.index + 1)
61+
name = var.staticvmname != null ? var.staticvmname : format("${var.vmname}${var.vmnameformat}", count.index + 1)
6262

6363
resource_pool_id = data.vsphere_resource_pool.pool.id
6464
folder = var.vmfolder
@@ -139,18 +139,18 @@ resource "vsphere_virtual_machine" "vm" {
139139

140140
customize {
141141
dynamic "linux_options" {
142-
for_each = var.is_windows_image ? [] : [1]
142+
for_each = var.is_windows_image ? [] : [1]
143143
content {
144-
host_name = var.instances == 1 ? var.vmname : format("${var.vmname}${var.vmnameformat}", count.index + 1)
145-
domain = var.vmdomain
144+
host_name = var.staticvmname != null ? var.staticvmname : format("${var.vmname}${var.vmnameformat}", count.index + 1)
145+
domain = var.domain
146146
hw_clock_utc = var.hw_clock_utc
147147
}
148148
}
149149

150150
dynamic "windows_options" {
151-
for_each = var.is_windows_image ? [1] : []
151+
for_each = var.is_windows_image ? [1] : []
152152
content {
153-
computer_name = var.instances == 1 ? var.vmname : format("${var.vmname}${var.vmnameformat}", count.index + 1)
153+
computer_name = var.staticvmname != null ? var.staticvmname : format("${var.vmname}${var.vmnameformat}", count.index + 1)
154154
admin_password = var.local_adminpass
155155
workgroup = var.workgroup
156156
join_domain = var.windomain
@@ -173,7 +173,7 @@ resource "vsphere_virtual_machine" "vm" {
173173
ipv4_netmask = "%{if length(var.ipv4submask) == 1}${var.ipv4submask[0]}%{else}${var.ipv4submask[network_interface.key]}%{endif}"
174174
}
175175
}
176-
dns_server_list = var.vmdns
176+
dns_server_list = var.dns_server_list
177177
dns_suffix_list = var.dns_suffix_list
178178
ipv4_gateway = var.vmgateway
179179
}

tests/smoke/apply.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
terraform init
2+
terraform fmt
3+
terraform validate
4+
terraform apply -var-file="private.tfvars"

variables.tf

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ variable "storage_policy_id" {
9393

9494
###########################################
9595
variable "vmname" {
96-
description = "The name of the virtual machine used to deploy the vms. When only one VM is requested, `vmname` is simply the name of the deployed VM."
96+
description = "The name of the virtual machine used to deploy the vms. This name can scale out based on number of instances and vmnameformat - example can be found under exampel folder"
9797
default = "terraformvm"
9898
}
9999

@@ -102,6 +102,11 @@ variable "vmnameformat" {
102102
default = "%02d"
103103
}
104104

105+
variable "staticvmname" {
106+
description = "Static name of the virtual machin. When this option is used VM can not scale out using instance variable. You can use for_each outside the module to deploy multiple static vms with different names"
107+
default = null
108+
}
109+
105110
variable "vmtemp" {
106111
description = "Name of the template available in the vSphere."
107112
}
@@ -144,7 +149,7 @@ variable "vmgateway" {
144149
default = null
145150
}
146151

147-
variable "vmdns" {
152+
variable "dns_server_list" {
148153
type = list(string)
149154
default = null
150155
}
@@ -244,7 +249,7 @@ variable "hw_clock_utc" {
244249
default = true
245250
}
246251

247-
variable "vmdomain" {
252+
variable "domain" {
248253
description = "default VM domain for linux guest customization."
249254
default = "Development.com"
250255
}

0 commit comments

Comments
 (0)