Is there any way with the terraform to determine which vmware vsphere datastore has the most free space?
When I'm provisioning I want to make sure my VMs end up on unique datastores (i.e. no two vms should end up on the same datastore) but also on datastores with the most free space.
So assume my datastores are named ds1, ds2, ds3, ds4, ds5, etc..
- ds1 is 99% used
- ds2 is 70% used
- ds3 is 10% used
- ds4 is 60% used
- ds5 is 5% used
I want ds5 to be used first (since it has the most free space), then ds3 (since we can't use ds5 since its already been used and ds3 has the second most free space) and so forth.
I see how to hard code a datastore, and I suppose I could prompt the user for the datastore to use but I'd prefer not to use such a static approach. Semi-defeats the purpose of automation!
From the command line of an ESXi host I can do something like this to get the datastores in order of most free space to least:
df | sort -n -r | grep VMFS-5 | awk '!/vm-host|datastore17|datastore18/' | awk '{print $6}' | awk '{print $NF}' FS=/ | awk NR==1
But there are a few issues with this:
1) I'm not sure how I can run this from inside of terraform against a remote ESXi host and get the response
2) An astute gentleman on the terraform gitter channel mentioned that if you ran terraform apply multiple times, because this value is dynamically determined/non-deterministic it might end up changing the VMs datastore
So I'm not sure how this can be done. I don't want to statically set it or have to prompt for it each time but maybe that's the only option. Does anyone else have any other ideas.
Certainly I can't be the first person to run into this need? :)