title: Terraform to customize the VM provisioned in the Vsphere Hypervisor
body: <p>I am able to provision the VM using Vsphere provider and join to the Domain, but when i tried to copy a file or execute powershell commands to the provisioned server, it is failing.
  in my template i have enabled count </p>
  
  <pre><code>resource "vsphere_virtual_machine" "vm" {
  
    count = var.vm_count
    resource_pool_id = data.vsphere_compute_cluster.cluster.resource_pool_id
  ....
  }
  </code></pre>
  
  <p>which will allow to create multiple vm's based on input validation</p>
  
  <p>in the windows customization</p>
  
  <pre><code>   customize {
        windows_options {
          computer_name = "${var.host_prefix}${count.index + 1}"
          join_domain           = "domainname"
          domain_admin_user     = "username"
          domain_admin_password = "password"
          time_zone             = "004"
        }
  </code></pre>
  
  <h2>enabled DHCP for</h2>
  
  <pre><code>  network_interface {
  
        }
  </code></pre>
  
  <p>with the above code i am able to create vm and add them to domain controller successfully.</p>
  
  <p>Post that, i would like to enable iis in each vm,  I have written the below code</p>
  
  <pre><code>  resource "null_resource" "example_provisioner" {
  
  
        connection {
          host =  "${var.host_prefix}${count.index + 1}"
          type  = "winrm"
          user  = "username"
          password = "password"
          insecure = false
          agent = true
        }
  
  
  
    // copy our example script to the server
    provisioner "file" {
      source      = "e://iis.ps1"
      destination = "c://iis.ps1"
    }
  
  
    // change permissions to executable and pipe its output into a new file
    provisioner "remote-exec" {
      inline = [
        "powershell.exe c://iis.ps1",
         ]
    }
    }
  </code></pre>
  
  <p>below is the error of the null provision when i use hostname = <code>"${var.host_prefix}${count.index + 1}".</code>
  PS E:\terraform\vmware> terraform plan
  var.host_prefix
    Enter a value: abchostname</p>
  
  <p>var.vm_count
    Enter a value: 1</p>
  
  <p>Error: Reference to "count" in non-counted context</p>
  
  <p>on base.tf line 140, in resource <code>"null_resource" "example_provisioner":</code></p>
  
  <pre><code> 140:     host = "${var.host_prefix}${count.index + 1}"
  </code></pre>
  
  <p>The "count" object can be used only in "resource" and "data" blocks, and only
  when the "count" argument is set.</p>
  
  <p>can somebody help me to run the powershell commands on newly provisioned vm's using vpshere resource with count parameters.</p>