Skip to content

Commit c21de86

Browse files
committed
Add vmstartcount functionality
1 parent afd258f commit c21de86

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ locals {
8080
resource "vsphere_virtual_machine" "vm" {
8181
count = var.instances
8282
depends_on = [var.vm_depends_on]
83-
name = "${var.staticvmname != null ? var.staticvmname : format("${var.vmname}${var.vmnameformat}", count.index + 1)}${var.fqdnvmname == true ? ".${var.domain}" : ""}"
83+
name = "${var.staticvmname != null ? var.staticvmname : format("${var.vmname}${var.vmnameformat}", count.index + var.vmstartcount)}${var.fqdnvmname == true ? ".${var.domain}" : ""}"
8484

8585
resource_pool_id = var.vmrp != "" ? data.vsphere_resource_pool.pool[0].id : var.vmrpid
8686
folder = var.vmfolder
@@ -218,7 +218,7 @@ resource "vsphere_virtual_machine" "vm" {
218218
dynamic "linux_options" {
219219
for_each = var.is_windows_image ? [] : [1]
220220
content {
221-
host_name = var.staticvmname != null ? var.staticvmname : format("${var.vmname}${var.vmnameformat}", count.index + 1)
221+
host_name = var.staticvmname != null ? var.staticvmname : format("${var.vmname}${var.vmnameformat}", count.index + var.vmstartcount)
222222
domain = var.domain
223223
hw_clock_utc = var.hw_clock_utc
224224
}
@@ -227,7 +227,7 @@ resource "vsphere_virtual_machine" "vm" {
227227
dynamic "windows_options" {
228228
for_each = var.is_windows_image ? [1] : []
229229
content {
230-
computer_name = var.staticvmname != null ? var.staticvmname : format("${var.vmname}${var.vmnameformat}", count.index + 1)
230+
computer_name = var.staticvmname != null ? var.staticvmname : format("${var.vmname}${var.vmnameformat}", count.index + var.vmstartcount)
231231
admin_password = var.local_adminpass
232232
workgroup = var.workgroup
233233
join_domain = var.windomain

variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ variable "vmnameformat" {
125125
default = "%02d"
126126
}
127127

128+
variable "vmstartcount" {
129+
description = "vmname start count value. default is set to 1. example: a value of 4 (with default format and 2 instances) will make first instance suffix 04 and second instance suffix 05"
130+
default = 1
131+
}
132+
128133
variable "staticvmname" {
129134
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"
130135
default = null

0 commit comments

Comments
 (0)