title: How to copy file with variable changed to value from local to remote using Terraform?
body: <p>I am using Terraform to create a <code>debian-cloud/debian-9</code> image on <a href="https://cloud.google.com/" rel="nofollow noreferrer">Google Cloud Platform</a>. I have a directory on local that I am copying to the created instance using <code>gcloud compute scp --recurse [LOCAL_DIR] [INSTANCE-NAME]:[REMOTE_LOCATION]</code>.
  <br>The directory on local has multiple <code>.conf</code> files which look something like below:</p>
  
  <pre><code>&lt;source&gt;
    @type tail
  
    format syslog
  
    path /var/log/syslog
    pos_file /var/lib/google-fluentd/pos/syslog.pos
    read_from_head true
  
    #Here's the variable I wanna replace
    tag ${instance-name}-syslog
  &lt;/source&gt;
  
  </code></pre>
  
  <p>I've created these <code>.conf</code> files and added the variable <strong>${instance-name}</strong>. Now I would like that variable to be replaced by the value of Terraform/linux environment variable.
  <br><br> for e.g: if a Terraform/linux environment variable has a value like "<strong><em>some-value</em></strong>", then <code>${instance-name}</code> from all the <code>.conf</code> files should be replaced by this and look something like below:</p>
  
  <pre><code>&lt;source&gt;
    @type tail
  
    format syslog
  
    path /var/log/syslog
    pos_file /var/lib/google-fluentd/pos/syslog.pos
    read_from_head true
  
    #Here's the variable I wanna replace
    tag some-value-syslog
  &lt;/source&gt;
  </code></pre>
  
  <p>I am looking to replace the value only on the remote (GCE instance) where I copied the directory, not in the files on my local.<br> Modifying the files to replace the variable on the server is also an acceptable option in my case, but I am not really sure if that is a good way to do this. If it is, I am not sure what script would read the files one by one and replace the variables.</p>
  
  <p><strong>EDIT : Adding the Terraform script to create a Debian instance and copy directory from local to server</strong></p>
  
  <pre><code>resource "google_compute_instance" "default" {
    name         = "${var.instance_name}"
    project      = "${var.project}"
    machine_type = "${var.machine-type}"
    zone         = "${var.instance-zone}"
  
    boot_disk {
      initialize_params {
        image = "debian-cloud/debian-9"
      }
    }
  
    network_interface {
      network = "default"
  
      access_config {
        // Ephemeral IP
      }
    }
  
  
    #If replace the variables using shell script, this script will be used
    metadata_startup_script = "replace_var.sh"
  
    #One way
    provisioner "local-exec" {
      command = "gcloud compute scp --recurse [LOCAL-DIR] ${var.instance_name}:/etc/google-fluentd"
    }
  
    #Another way
    provisioner "file" {
      source      = "[LOCAL-DIR]"
      destination = "/etc/google-fluentd"
    }
  }
  </code></pre>