title: How to run custom scripts post terraform vmware vm deployment?
body: <p>I have been researching on this topic for over a week now and couldn't find any good solution neither on terraform documentation site nor on the web.</p>
  
  <p>Main issue trying to solve right now is: how to run a custom powershell script at the end of terraform vmware basic windows server 2016 vm build.</p>
  
  <p>Tried following methods:</p>
  
  <ul>
  <li><code>remote-exec</code> - fail</li>
  <li>provisioners inside vm resource definition - fail</li>
  <li>null resource - Error: timeout - last error: http response error: 401 - invalid content type</li>
  </ul>
  
  <p>Here's my null resource definition right below vm resource build within the same <code>main.tf</code> file</p>
  
  <pre><code>resource "null_resource" "vm" {
    triggers = {
      public_ip = &lt;host ip address&gt;
    }
  
    connection {
      type = "winrm"
      host = &lt;host ip address&gt;
      user = &lt;username&gt;
      password = &lt;password&gt;
      agent = false
    }
  
    provisioner "file" {
      source      = "userdata.ps1"
      destination = "C:/Windows"
    }
  
    provisioner "remote-exec" {
      inline = [
        "powershell.exe -ExecutionPolicy Bypass -File C:/Windows/userdata.ps1"
      ]
    }
  }
  </code></pre>
  
  <p>Please suggest what are the recommended practices and your working solution</p>