Deploy servers from CSV?

552 views
Skip to first unread message

Raj Wurttemberg

unread,
Mar 7, 2019, 9:38:45 AM3/7/19
to Terraform
Hello,

I just discovered Terraform yesterday and it looks like a really cool tool.  I have been reading about Terraform for a few hours and learning what it can do. 

We frequently deploy 10 to 100 servers at a time for customers, we do have a process but it is painful and error-prone. It is also difficult because customers specify their own specifications to us in an Excel spreadsheet. Can Terraform deploy servers from a CSV?  For example, I have a CSV like the one below.  

VM_Name,hostname,Notes,OS,RAM,CPU,Datacenter,Domain Name,VLAN ID,IP,MASK,GW,DNS1,DNS2,Datastore,Vmware Cluster,Resource Pool,Time Zone
vm001,dbserver01,Test DB server,RHEL76,128,8,TDC01,domain.com,2222,10.11.0.15,255.255.255.0,10.11.0.1,8.8.8.8,8.8.4.4,dstest01,testclust01,testrp01,GMT
vm002,appserver01,Test app server,RHEL76,64,4,TDC01,domain.com,2222,10.11.0.16,255.255.255.0,10.11.0.1,8.8.8.8,8.8.4.4,dstest02,testclust01,testrp01,GMT
vm003,webserver01,Test web server,RHEL76,16,2,TDC01,domain.com,2222,10.11.0.17,255.255.255.0,10.11.0.1,8.8.8.8,8.8.4.4,dstest02,testclust01,testrp01,GMT


Is it possible for Terraform to ingest this CSV file and create a batch of VMware virtual machines?

Thanks,
/Raj

Anshu Prateek

unread,
Mar 7, 2019, 9:48:55 AM3/7/19
to terrafo...@googlegroups.com
You will need some external scripts to massage the input into required terraform code but it’s doable.

TF supports VMware vsphere if that’s what you need.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/917e2e6a-cced-4941-b3eb-326655ae7ca1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Linux Ninja

unread,
Mar 7, 2019, 12:00:34 PM3/7/19
to terrafo...@googlegroups.com
A simple shell script should be able to parse the CSV into env vars and call Terraform as a quick proof-of-concept.
You'd write a set of resources that use these inputs and create it as a module you would call for each line.

Not a lot of work, but not the primary use case for Terraform.

Raj Wurttemberg

unread,
Mar 7, 2019, 4:28:09 PM3/7/19
to Terraform
OK, so Terraform can't have an input file of a list of servers to deploy?  

Do you have any example scripts for a mass-VMware deployment?

Thanks!
/Raj

Linux Ninja

unread,
Mar 7, 2019, 6:31:16 PM3/7/19
to terrafo...@googlegroups.com
Terraform's usage leads to defining the desired infrastructure using code. This means you don't just feed it a list, you define the end state entirely. But, using modules, you have re-usable code that you can use to stand up a vm, but call that module from another source for each vm you want to create.

So, you would convert that csv into a set of terraform stanzas that each call the module. This is just a quick example.

If you're looking for a code sample, I think it can be done easily.

Steve Gold

unread,
Jul 30, 2019, 10:20:37 AM7/30/19
to Terraform
I agree it would be great if Terraform allowed for away to use an external csv for the input of Variables. CSVDECODE works for some of the Variables needed to create a VM, but were you need to convert the plain text description of a variable to  the UUID I have not been able to get it to work. If I have 10 VM's that need to be placed in 10 different DataStores, I am going to have to create 10 different resource instances for each. That is not an effective use of code, nor allows me to scale.

locals {
  virtualmachines = csvdecode(file("${path.module}/virtualmachines.csv"))
}

.......

resource "vsphere_virtual_machine" "vm" {
  count = length(local.virtualmachines)

  name             = local.virtualmachines[count.index].vname
  resource_pool_id = "${data.vsphere_resource_pool.pool.id}"
  datastore_id     = "${data.vsphere_datastore.datastore.id}"

  num_cpus                   = local.virtualmachines[count.index].cpu
  memory                     = local.virtualmachines[count.index].memory
  guest_id                   = local.virtualmachines[count.index].guest_id
  wait_for_guest_net_timeout = 0
Reply all
Reply to author
Forward
0 new messages