Skip to content

Instantly share code, notes, and snippets.

@zpratt
Created January 3, 2019 05:23
Show Gist options
  • Save zpratt/0ad7bcf382b321501bd92e958bf9f8a9 to your computer and use it in GitHub Desktop.
Save zpratt/0ad7bcf382b321501bd92e958bf9f8a9 to your computer and use it in GitHub Desktop.
vcsim attempt (and fail)
vsphere_user="user"
vsphere_password="pass"
vsphere_host = "127.0.0.1:8989"
datacenter = "DC0"
cluster = "DC0_H0"
datastore = "datastore/LocalDS_0"
clustered_datastore = ""
network = "network/VM Network"
gateway = "192.168.1.1"
vm_folder = "vcsim-test-folder"
vm_name = "vcsim-test"
subnet_mask = "24"
ips = [
"10.134.3.162",
"10.134.3.163"
]
resource "vsphere_folder" "inventory_folder" {
path = "${var.vm_folder}"
type = "vm"
datacenter_id = "${data.vsphere_datacenter.datacenter.id}"
}
resource "vsphere_virtual_machine" "test-node" {
count = "${length(var.ips)}"
name = "${var.vm_name}-master-${count.index}"
resource_pool_id = "${data.vsphere_resource_pool.pool.id}"
datastore_id = "${data.vsphere_datastore.datastore.id}"
num_cpus = 2
memory = 8192
folder = "${vsphere_folder.inventory_folder.path}"
network_interface {
network_id = "${data.vsphere_network.network.id}"
adapter_type = "vmxnet3"
}
disk {
label = "${var.vm_name}-master-${count.index}-disk"
size = "20"
thin_provisioned = true
unit_number = 0
}
}
variable "vsphere_user" {
type = "string"
}
variable "vsphere_password" {
type = "string"
}
variable "vsphere_host" {
type = "string"
}
variable "datacenter" {
type = "string"
}
variable "cluster" {
type = "string"
}
variable "datastore" {
type = "string"
}
variable "network" {
type = "string"
}
variable "vm_name" {
type = "string"
}
variable "vm_folder" {
type = "string"
}
variable "clustered_datastore" {
type = "string"
}
variable "gateway" {
type = "string"
}
variable "ips" {
type = "list"
}
variable "subnet_mask" {
default = ""
}
provider "vsphere" {
user = "${var.vsphere_user}"
password = "${var.vsphere_password}"
vsphere_server = "${var.vsphere_host}"
allow_unverified_ssl = true
version = "~> 1.9"
}
data "vsphere_datacenter" "datacenter" {
name = "${var.datacenter}"
}
data "vsphere_datastore" "datastore" {
name = "${var.datastore}"
datacenter_id = "${data.vsphere_datacenter.datacenter.id}"
}
data "vsphere_network" "network" {
name = "${var.network}"
datacenter_id = "${data.vsphere_datacenter.datacenter.id}"
}
data "vsphere_resource_pool" "pool" {
name = "${var.cluster}/Resources"
datacenter_id = "${data.vsphere_datacenter.datacenter.id}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment