title: Can Terraform watch a directory for changes?
body: <p>I want to monitor a directory of files, and if one of them changes, to re-upload and run some other tasks. My previous solution involved monitoring the individual files, but this is error-prone as some files may be forgotten:</p>
  
  <pre><code>resource "null_resource" "deploy_files" {    
    triggers = {
      file1 = "${sha1(file("my-dir/file1"))}"
      file2 = "${sha1(file("my-dir/file2"))}"
      file3 = "${sha1(file("my-dir/file3"))}"
      # have I forgotten one?
    }
  
    # Copy files then run a remote script.
    provisioner "file" { ... }
    provisioner "remote-exec: { ... }
  }
  </code></pre>
  
  <p>My next solution is to take a hash of the directory structure in one resource, and use this hash as a trigger in the second:</p>
  
  <pre><code>resource "null_resource" "watch_dir" {
    triggers = {
      always = "${uuid()}"
    }
  
    provisioner "local-exec" {
      command = "find my-dir  -type f -print0 | xargs -0 sha1sum | sha1sum &gt; mydir-checksum"
    }
  }
  
  
  resource "null_resource" "deploy_files" {    
    triggers = {
      file1 = "${sha1(file("mydir-checksum"))}"
    }
  
    # Copy files then run a remote script.
    provisioner "file" { ... }
    provisioner "remote-exec: { ... }
  }
  </code></pre>
  
  <p>This works okay, except changes to <code>mydir-checksum</code> are only picked up after the first <code>apply</code>. So I need to <code>apply</code> twice, which isn't great. It's a bit of a kludge.</p>
  
  <p>I can't see a more obvious way to monitor an entire directory for changes in content. Is there a standard way to do this?</p>