tenstad / terraform-provider-remote

Manage remote files with terraform
https://registry.terraform.io/providers/tenstad/remote/latest/docs
Mozilla Public License 2.0
15 stars 7 forks source link

Add modification timestamp or other way to reliably indicate change. #70

Open Patricol opened 2 years ago

Patricol commented 2 years ago

Hello! Thanks for the provider.

Currently, id is deterministic, and I don't see any other attributes that can be used to reliably trigger, for example, a null_resource whenever remote_file is applied.

A more specific example:

resource "remote_file" "iscsi" {
  content = local.content
  path = local.path
}

resource "null_resource" "restoreconfig" {
  triggers = {
    content = sha256(remote_file.iscsi.content)
    file = remote_file.iscsi.id
  }
  provisioner "remote-exec" {
    inline = ["targetcli restoreconfig savefile=${remote_file.iscsi.path} clear_existing=True"]
  }
}

If something else changes the contents of the file; applying again will change the file back, but will not rerun restoreconfig. remote_file doesn't currently have any documented attributes that can solve this problem.

tenstad commented 2 years ago

Hi! We could add a last_modified timestamp to the remote_file resource (at least the remote_file data source). That would solve your problem, right? But I wonder why something else would change the file. Is terraform not considered the owner and sole editor of the file?

Another thought, could you use a remote_file data source to read the current file content, and trigger the provisioner only if the current and desired content differ?