Skip to content

Commit

Permalink
Add vmstartcount functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
damnsam committed Jun 15, 2023
1 parent afd258f commit c21de86
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 3 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ locals {
resource "vsphere_virtual_machine" "vm" {
count = var.instances
depends_on = [var.vm_depends_on]
name = "${var.staticvmname != null ? var.staticvmname : format("${var.vmname}${var.vmnameformat}", count.index + 1)}${var.fqdnvmname == true ? ".${var.domain}" : ""}"
name = "${var.staticvmname != null ? var.staticvmname : format("${var.vmname}${var.vmnameformat}", count.index + var.vmstartcount)}${var.fqdnvmname == true ? ".${var.domain}" : ""}"

resource_pool_id = var.vmrp != "" ? data.vsphere_resource_pool.pool[0].id : var.vmrpid
folder = var.vmfolder
Expand Down Expand Up @@ -218,7 +218,7 @@ resource "vsphere_virtual_machine" "vm" {
dynamic "linux_options" {
for_each = var.is_windows_image ? [] : [1]
content {
host_name = var.staticvmname != null ? var.staticvmname : format("${var.vmname}${var.vmnameformat}", count.index + 1)
host_name = var.staticvmname != null ? var.staticvmname : format("${var.vmname}${var.vmnameformat}", count.index + var.vmstartcount)
domain = var.domain
hw_clock_utc = var.hw_clock_utc
}
Expand All @@ -227,7 +227,7 @@ resource "vsphere_virtual_machine" "vm" {
dynamic "windows_options" {
for_each = var.is_windows_image ? [1] : []
content {
computer_name = var.staticvmname != null ? var.staticvmname : format("${var.vmname}${var.vmnameformat}", count.index + 1)
computer_name = var.staticvmname != null ? var.staticvmname : format("${var.vmname}${var.vmnameformat}", count.index + var.vmstartcount)
admin_password = var.local_adminpass
workgroup = var.workgroup
join_domain = var.windomain
Expand Down
5 changes: 5 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ variable "vmnameformat" {
default = "%02d"
}

variable "vmstartcount" {
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"
default = 1
}

variable "staticvmname" {
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"
default = null
Expand Down

0 comments on commit c21de86

Please sign in to comment.