title: How can I use Terraform's file provisioner to copy from my local machine onto a VM?
body: <p>I'm new to Terraform and have so far managed to get a basic VM (plus Resource Manager trimmings) up and running on Azure. The next task I have in mind is to have Terraform copy a file from my local machine into the newly created instance. Ideally I'm after a solution where the file will be copied each time the apply command is run.</p>
  
  <p>I feel like I'm pretty close but so far I just get endless "Still creating..." statements once I apply (the file is 0kb so after a couple of mins it feels safe to give up).</p>
  
  <p>So far, this is what I've got (based on this code): <a href="https://stackoverflow.com/a/37866044/4941009">https://stackoverflow.com/a/37866044/4941009</a></p>
  
  <p><strong>Network</strong></p>
  
  <pre><code>resource "azurerm_public_ip" "pub-ip" {
      name = "PublicIp"
      location = "${var.location}"
      resource_group_name = "${azurerm_resource_group.rg.name}"
      public_ip_address_allocation = "Dynamic"
      domain_name_label = "${var.hostname}"
  }
  </code></pre>
  
  <p><strong>VM</strong></p>
  
  <pre><code>resource "azurerm_virtual_machine" "vm" {
    name                  = "${var.hostname}"
    location              = "${var.location}"
    resource_group_name   = "${azurerm_resource_group.rg.name}"
    vm_size               = "${var.vm_size}"
    network_interface_ids = ["${azurerm_network_interface.nic.id}"]
  
    storage_image_reference {
      publisher = "${var.image_publisher}"
      offer     = "${var.image_offer}"
      sku       = "${var.image_sku}"
      version   = "${var.image_version}"
    }
  
    storage_os_disk {
      name          = "${var.hostname}osdisk1"
      vhd_uri       = "${azurerm_storage_account.stor.primary_blob_endpoint}${azurerm_storage_container.cont.name}/${var.hostname}osdisk.vhd"
      os_type       = "${var.os_type}"
      caching       = "ReadWrite"
      create_option = "FromImage"
    }
  
    os_profile {
      computer_name  = "${var.hostname}"
      admin_username = "${var.admin_username}"
      admin_password = "${var.admin_password}"
    }
  
    os_profile_windows_config {
      provision_vm_agent = true
    }
  
    boot_diagnostics {
      enabled     = true
      storage_uri = "${azurerm_storage_account.stor.primary_blob_endpoint}"
    }
  
    tags {
        environment = "${var.environment}"
    }
  }
  </code></pre>
  
  <p><strong>File Provisioner</strong></p>
  
  <pre><code>resource "null_resource" "copy-test-file" {
  
    connection {
      type     = "ssh"
      host     = "${azurerm_virtual_machine.vm.ip_address}"
      user     = "${var.admin_username}"
      password = "${var.admin_password}"
    }
  
    provisioner "file" {
      source      = "test.txt"
      destination = "/tmp/test.txt"
    }
  
  }
  </code></pre>
  
  <p>As an aside, if I pass incorrect login details to the provisioner (ie rerun this after the VM has already been created and supply a different password to the provisioner) the behaviour is the same. Can anyone suggest where I'm going wrong?</p>