deploying a multi VM test environment multiple times with terraform

179 views Asked by At

I'm still sorta neweb & a pleb with terraform so looking for direction or where I can find the info on how to go about this. What I'm trying to bring up looks like this

7 different VM's times X ( this can change depending on what is needed) forgot to note this but I'm doing this in vShpere as well (I know the count is hardcoded for now & is just me testing & learning for now)

I know I can utilize the count option & add each VM as a different resource option but doing this will probably cause the SAN to bomb out & was wondering is there a way to do this VM by VM. Sry if the way this is worded isn't well thought out or put together too.

To note not looking for the actual code on how to do it just the direction of where I can go to read up/ get examples of it to figure it out myself. I shall continue my google hunting in the meantime as well & thnx. Bellow is the mark1 version of the main.tf file for it currently. any help would be much appreciated & thnx

# Setup vSphere Provider and login thingz
provider "vsphere" {
  user           = var.username
  password       = var.password
  vsphere_server = var.vcenter

  # if you have a self-signed cert
  allow_unverified_ssl = true
}
# Data & info from vshere
data "vsphere_datacenter" "dc" {
  name = var.datacenter
}

data "vsphere_datastore_cluster" "datastore_cluster" {
  name          = var.datastore
  datacenter_id = "${data.vsphere_datacenter.dc.id}"
}

data "vsphere_datastore" "iso_datastore" {
  name          = var.iso_datastore
  datacenter_id = "${data.vsphere_datacenter.dc.id}"
}

data "vsphere_compute_cluster" "cluster" {
  name          = var.cluster
  datacenter_id = "${data.vsphere_datacenter.dc.id}"
}

data "vsphere_network" "network" {
  name          = var.network
  datacenter_id = "${data.vsphere_datacenter.dc.id}"
}

data "vsphere_virtual_machine" "template" {
  name          = var.template
  datacenter_id = "${data.vsphere_datacenter.dc.id}"
}

data "vsphere_virtual_machine" "template2" {
  name          = var.template2
  datacenter_id = "${data.vsphere_datacenter.dc.id}"
}

#Machines being cloned out 
resource "vsphere_virtual_machine" "vm" {
  name             = "Zaku-win10-${count.index + 1}"
  count = 2
  resource_pool_id = data.vsphere_compute_cluster.cluster.resource_pool_id
  datastore_cluster_id  = data.vsphere_datastore_cluster.datastore_cluster.id
  num_cpus         = var.numcpus
  memory           = var.numram
  guest_id         = data.vsphere_virtual_machine.template.guest_id
  scsi_type        = data.vsphere_virtual_machine.template.scsi_type
  network_interface {
    network_id   = data.vsphere_network.network.id
    adapter_type = data.vsphere_virtual_machine.template.network_interface_types[0]
  }
  disk {
    label            = "disk0"
    size             = data.vsphere_virtual_machine.template.disks.0.size
    thin_provisioned = data.vsphere_virtual_machine.template.disks.0.thin_provisioned
  }
  clone {
    template_uuid = data.vsphere_virtual_machine.template.id

  }
}

resource "vsphere_virtual_machine" "vm2" {
  name             = "Zaku-testy-${count.index + 1}"
  count = 3
  resource_pool_id = data.vsphere_compute_cluster.cluster.resource_pool_id
  datastore_cluster_id  = data.vsphere_datastore_cluster.datastore_cluster.id
  num_cpus         = var.numcpus
  memory           = var.numram
  guest_id         = data.vsphere_virtual_machine.template.guest_id
  scsi_type        = data.vsphere_virtual_machine.template.scsi_type
  network_interface {
    network_id   = data.vsphere_network.network.id
    adapter_type = data.vsphere_virtual_machine.template.network_interface_types[0]
  }
  disk {
    label            = "disk0"
    size             = data.vsphere_virtual_machine.template.disks.0.size
    thin_provisioned = data.vsphere_virtual_machine.template.disks.0.thin_provisioned
  }
  clone {
    template_uuid = data.vsphere_virtual_machine.template.id

  }
}
0

There are 0 answers