Skip to content

Commit 76a01f9

Browse files
Merge pull request #139 from lgatellier/feat/variable-vmrpid
Handle new vmrpid variable - Add new vmrpid variable to allow users to provide a resource pool id instead of a resource pool path. This can be used, for exemple, to link the vSphere VM to a vsphere_vapp_container also managed by terraform.
2 parents 3920a4b + 881a04c commit 76a01f9

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ data "vsphere_datastore" "disk_datastore" {
2121
}
2222

2323
data "vsphere_resource_pool" "pool" {
24+
count = var.vmrp != "" ? 1 : 0
2425
name = var.vmrp
2526
datacenter_id = data.vsphere_datacenter.dc.id
2627
}
@@ -81,7 +82,7 @@ resource "vsphere_virtual_machine" "vm" {
8182
depends_on = [var.vm_depends_on]
8283
name = var.staticvmname != null ? var.staticvmname : format("${var.vmname}${var.vmnameformat}", count.index + 1)
8384

84-
resource_pool_id = data.vsphere_resource_pool.pool.id
85+
resource_pool_id = var.vmrp != "" ? data.vsphere_resource_pool.pool[0].id : var.vmrpid
8586
folder = var.vmfolder
8687
tags = var.tag_ids != null ? var.tag_ids : data.vsphere_tag.tag[*].id
8788
custom_attributes = var.custom_attributes

output.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ output "DC_ID" {
55

66
output "ResPool_ID" {
77
description = "Resource Pool id"
8-
value = data.vsphere_resource_pool.pool.id
8+
value = var.vmrp != "" ? data.vsphere_resource_pool.pool[0].id : var.vmrpid
99
}
1010

1111
output "VM" {

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,14 @@ variable "dc" {
175175
description = "Name of the datacenter you want to deploy the VM to."
176176
}
177177

178+
variable "vmrpid" {
179+
description = "ID of cluster resource pool that VM will be deployed to. you use following to choose default pool in the cluster (esxi1) or (Cluster)/Resources."
180+
default = ""
181+
}
182+
178183
variable "vmrp" {
179184
description = "Cluster resource pool that VM will be deployed to. you use following to choose default pool in the cluster (esxi1) or (Cluster)/Resources."
185+
default = ""
180186
}
181187

182188
variable "vmfolder" {

0 commit comments

Comments
 (0)