terraform {
  required_version = ">= 0.12"
  backend "local" {
  }
  required_providers {
    esxi = {
      source = "qindel.com/narenas/esxi"
      version = "~> 0.1"
    }
  }
}

provider "esxi" {
  esxi_hostname     = "esxi-jenkins.evlt.uma.es"
  esxi_hostport     = "22"
  esxi_hostssl      = "443"
  esxi_username     = "root"
  esxi_password     = var.vi_password
}

resource "esxi_guest" "modelo" {
  guest_name        = format("og-%s-modelo", var.ogversion)
  disk_store        = "ds.dell-esx09"
  memsize           = 1024
  power             = "off"
  numvcpus          = 1
  clone_from_vm     = "plantilla-modelo"
  nested_esxi       = "y"

  network_interfaces {
    virtual_network = var.virtual_network
    nic_type        = "e1000"
    mac_address     =  format("%s:ff",var.mac_prefix)
  }
}

resource "esxi_guest" "cliente" {
  count             = var.num_clients
  guest_name        = format("og-%s-pc%02d", var.ogversion, count.index)
  disk_store        = "ds.dell-esx09"
  boot_disk_size    = 50
  memsize           = 1024
  power             = "off"
  numvcpus          = 1
  nested_esxi       = "y"

  network_interfaces {
    virtual_network = var.virtual_network
    nic_type        = "e1000"
    mac_address     =  format("%s:%s",var.mac_prefix, sum([11 , count.index]))
  }
}
