m_pahlevanzadeh
Enthusiast
Enthusiast

use a cluster in terraform

I need to tell terraform to use cluster "my_cluster" for creating a vm such as :

resource "vsphere_virtual_machine" "my_vm" {
name = "${var.ENVIRONMENT_CONTEXT__VARIABLES__VM_NAME}"
resource_pool_id = "${data.vsphere_host.host.resource_pool_id}"
datastore_id = data.vsphere_datastore.datastore.id

num_cpus = var.ENVIRONMENT_CONTEXT__VARIABLES__VM_CPU
memory = var.ENVIRONMENT_CONTEXT__VARIABLES__VM_RAM
guest_id = var.ENVIRONMENT_CONTEXT__VARIABLES__VM_GUEST_ID

 

network_interface {
network_id = "${data.vsphere_network.network.id}"
}

network_interface{
network_id = "${vsphere_distributed_port_group.pg_mgm.id}"
}

disk {
label = "${var.ENVIRONMENT_CONTEXT__VARIABLES__VM_NAME}_disk"
thin_provisioned = false
eagerly_scrub = true
size = 25
}

clone {
template_uuid = data.vsphere_virtual_machine.template.id
customize {
linux_options {
host_name = "${var.ENVIRONMENT_CONTEXT__VARIABLES__VM_NAME}"
domain = var.ENVIRONMENT_CONTEXT__VARIABLES__VM_DOMAIN
}
network_interface {
ipv4_address = var.ENVIRONMENT_CONTEXT__VARIABLES__VM_STATIC_IPV4_ADDRESS
ipv4_netmask = var.ENVIRONMENT_CONTEXT__VARIABLES__IPV4_NETMASK
}

network_interface{
ipv4_address = "192.168.119.168"
ipv4_netmask = "24"
}
ipv4_gateway = var.ENVIRONMENT_CONTEXT__VARIABLES__IPV4_GATEWAY

timeout = 50
}
}

}
}

How can I tell terraform to use my cluster?

0 Kudos
1 Reply
kollzey
Contributor
Contributor

add your cluster using data field

data "vsphere_compute_cluster" "name you want to reference cluster as in terraform code" {
  name = "name of cluster"
 
then add it in your resource block
compute_cluster_id = data.vsphere_compute_cluster.name of cluster.id
Tags (1)
0 Kudos