# Need help with per VM datastore selection on deployment

**URL:** <https://discuss.hashicorp.com/t/need-help-with-per-vm-datastore-selection-on-deployment/14688>\
**Category:** Terraform\
**Created:** [September 25, 2020, 8:56am UTC](https://discuss.hashicorp.com/t/need-help-with-per-vm-datastore-selection-on-deployment/14688 "2020-09-25T08:56:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marco2G](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/marco2g/32/12061_2.png) [@Marco2G](https://discuss.hashicorp.com/u/Marco2G)\
**Post date:** [September 25, 2020, 8:56am UTC](https://discuss.hashicorp.com/t/need-help-with-per-vm-datastore-selection-on-deployment/14688/1 "2020-09-25T08:56:31Z")

</div>

Hi everybody

We have cobbled together a Terraform script to deploy a customer’s linux VMs. Now the customer has grown from one datastore to two and I’m running into a brick wall.

My target is to be able to put the datastore name into X.auto.tfvars for each single vm.

I had tried defining a map variable matching the paths in vsphere to these names:

datastores = {  
customer\_X\_glb1 = “EMC Umgebung/customers/X/customer\_X\_glb1”  
customer\_X\_glb2 = “EMC Umgebung/customers/X/customer\_X\_glb2”  
}

Then in data\_sources.tf I defined this:

data “vsphere\_datastore” “customer\_X\_glb1” {  
name = var.datastores[“customer\_X\_glb1”]  
datacenter\_id = data.vsphere\_datacenter.dc.id  
}

data “vsphere\_datastore” “customer\_X\_glb2” {  
name = var.datastores[“customer\_X\_glb2”]  
datacenter\_id = data.vsphere\_datacenter.dc.id  
}

And in the vm resource in resources.tf:

datastore\_id = data.vsphere\_datastore.[element(var.Prod\_VMs,count.index).datastore].id

This is not allowed it seems.

Other things I’ve tried involved putting the per vm reference directly in data\_sources.tf but that didn’t work either.

I’m sure this is a simple and obvious problem but I’m afraid Terraform and I just aren’t compatible…

Can anybody help?
