Re-triggering shell script in terraform

Hi,

You could add a triggers block to the null_resource with the sha256 hash of the script contents.
That way when the script changes, the hash changes, triggering the null_resource to re-apply.


Something like:

resource "null_resource" "run_script" {
  triggers = {
    script_hash = "${sha256(var.bash_script)}"
  }
...
}

The sha256 hash is optional, but might help keep your .tfstate a little more compact if you use this pattern a lot (so the whole bash script isn’t stored in the state file repeatedly).