I’m trying to create virtual machines on VMware vSphere through Terraform. With following script, terraform init
works well but the error occurs when I executed terraform apply
.
data "vsphere_resource_pool" "pool" {
name = "Resources"
datacenter_id = "${data.vsphere_datacenter.dc.id}"
}
data "vsphere_virtual_machine" "template" {
name = "/${var.vsphere-datacenter}/myfolder/${var.vsphere-template-folder}/${var.vm-template-name}"
resource_pool_id = data.vsphere_resource_pool.pool.id
datacenter_id = data.vsphere_datacenter.dc.id
}
Error: Unsupported argument
on main.tf line 41, in data "vsphere_virtual_machine" "template":
41: resource_pool_id = "${data.vsphere_resource_pool.pool.id}"
An argument named "resource_pool_id" is not expected here.
What is the problem? This is my entire Terraform script.
# =================== #
# Deploying VMware VM #
# =================== #
# Connect to VMware vSphere vCenter
provider "vsphere" {
user = var.vsphere-user
password = var.vsphere-password
vsphere_server = var.vsphere-vcenter
# If you have a self-signed cert
allow_unverified_ssl = var.vsphere-unverified-ssl
}
# Define VMware vSphere
data "vsphere_datacenter" "dc" {
name = var.vsphere-datacenter
}
data "vsphere_datastore" "datastore" {
name = var.vm-datastore
datacenter_id = data.vsphere_datacenter.dc.id
}
data "vsphere_resource_pool" "pool" {
name = "Resources"
datacenter_id = "${data.vsphere_datacenter.dc.id}"
}
# (I don't use any clusters)
# data "vsphere_compute_cluster" "cluster" {
# name = var.vsphere-cluster
# datacenter_id = data.vsphere_datacenter.dc.id
# }
data "vsphere_network" "network" {
name = var.vm-network
datacenter_id = data.vsphere_datacenter.dc.id
}
data "vsphere_virtual_machine" "template" {
name = "/${var.vsphere-datacenter}/myfolder/${var.vsphere-template-folder}/${var.vm-template-name}"
resource_pool_id = data.vsphere_resource_pool.pool.id
datacenter_id = data.vsphere_datacenter.dc.id
}
# Create VMs
resource "vsphere_virtual_machine" "vm" {
count = var.vm-count
name = "${var.vm-name}-${count.index + 1}"
resource_pool_id = data.vsphere_virtual_machine.template.resource_pool_id
datastore_id = data.vsphere_datastore.datastore.id
num_cpus = var.vm-cpu
memory = var.vm-ram
guest_id = var.vm-guest-id
network_interface {
network_id = data.vsphere_network.network.id
}
disk {
label = "${var.vm-name}-${count.index + 1}-disk"
size = 25
}
clone {
template_uuid = data.vsphere_virtual_machine.template.id
customize {
timeout = 0
linux_options {
host_name = "node-${count.index + 1}"
domain = var.vm-domain
}
network_interface {}
}
}
}