'Replace the folder with file Provisioner terraform

I am trying to update the folder placed on ec2 by terraform file provisioner. If you are applying this for the first time it works fine but for the second time when I apply terraform apply it does not reflect the new changes to the copied folder. Any help would be appreciated

resource "null_resource" "code" {
  depends_on = [local_file.host_file]

  triggers = {
    always_run = timestamp()
  }

  provisioner "file" {
    source      = "../src"
    destination = "/home/ec2-user/src/"

    connection {
      type        = "ssh"
      host        = aws_instance.bastion.public_ip
      user        = "ec2-user"
      private_key = file("/tmp/keys/ec2-key")
      insecure    = true
    }
  }
}



Solution 1:[1]

The behavior is expected and is by design. There's currently an open issue for this.

This post however has a good workaround that you can use to solve the problem.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Paolo