loafoe/terraform-provider-ssh

ssh_resource provider doesn't seem to be updating file if it has changed nor is it re-running commands

Closed this issue · 1 comments

Thanks for this great tool. I just have one issue to raise.

It seems that once the provider has run, that even if the content changes and terraform indicates it will run again, that the new file is not uploaded, nor are the commands executed. Is this expected behavior and if so how do I configure it so that it should upload the new file and run the commands again?

Here is an example of my terraform

data "local_file" "interactive-finish-install-script" {
  filename = "${path.module}/mypath/finish-install.sh"
}

resource "ssh_resource" "myhost-interactive-finish-install-script" {
  host = '1.2.3.4'
  user = "root"
  private_key = file("/Users/myuser/.ssh/id_rsa")

  file {
    content = data.local_file.interactive-finish-install-script.content
    destination = "/root/finish-install.sh"
  }

  commands = [
   "chmod 700 /root/finish-install.sh"
  ]
}

So when my local finish-install.sh is updated, terraform plan indicates that ssh_resource.myhost-interactive-finish-install-script will run, but actually the new content is not uploaded nor do the commands run either.

I would like to make it such that if either the content or the commands are changed that it would execute again.

Thanks!

What you describe is indeed the expected behaviour. One option is to force recreation of the resource whenever a file or command content changes but that means effectively you would need to have a single file and single command per resource, unless the other commands are idempotent?

I'll recreate your setup and do some debugging. The file changes should be propagated at least. Thanks for the bug report!