Terraform tips and tricks

NOTE: this is WIP

Terraform provider VMware

Get Informations

variable "hosts" {
default = [
"esx-01.example.com",
"esx-02.example.com",
"esx-03.example.com"
]
}
data "vsphere_resource_pool" "resource_pool" {
count = length(var.hosts)
name = "${data.vsphere_host.hosts.*.name[count.index]}/Resources"
datacenter_id = "${data.vsphere_datacenter.dc.id}"
}
output "resourcepool_by_hosts" {
value = data.vsphere_resource_pool.resource_pool
}

Get your hosts resourcepool ID by selecting the resourcepools

variable "hosts" {
default = [
"esx-01.example.com",
"esx-02.example.com",
"esx-03.example.com"
]
}
data "vsphere_host" "hosts" {
count = length(var.hosts)
name = var.hosts[count.index]
datacenter_id = data.vsphere_datacenter.dc.id
}
output "resourcepool_by_resourcepool" {
value = data.vsphere_host.hosts
}

The Module call:

module "kcluster_db" {
source = "../terraform/modules/terraform-module-vmware_vm"
host_count = 1
name = "kcluster-db"
domain = "domain.local"
resource_pool_id = "resgroup-13"
datastore_id = data.vsphere_datastore.datastore_esx.id
num_cpus = "1"
mem_in_mb = "2048"
guest_id = "debian9Guest"
scsi_type = data.vsphere_virtual_machine.template_debian10.scsi_type
network_id = data.vsphere_network.network.id
adapter_type = data.vsphere_virtual_machine.template_debian10.network_interface_types[0]
size = "20"
eagerly_scrub = data.vsphere_virtual_machine.template_debian10.disks.0.eagerly_scrub
thin_provisioned = data.vsphere_virtual_machine.template_debian10.disks.0.thin_provisioned
template_uuid = data.vsphere_virtual_machine.template_debian10.id
}

Import the existing VM into the Terraform State:

terraform import module.kcluster_db.vsphere_virtual_machine.kcluster_masters /path/vm/kcluster-db.domain.local

Working as a IT-Operations engineer at NeXenio, a spin-off by Hasso-Plattner-Institute for products around a digitial workspace.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store