Unexpected Behavior with Terraform Local-Exec Provisioner Not Running on Resource Update
I'm maintaining legacy code that I'm optimizing some code but I've looked through the documentation and I'm still confused about I'm facing an issue with the local-exec provisioner in my Terraform configuration that doesn't seem to execute when I update an existing resource... I have a simple setup where I'm using the local-exec provisioner to run a script every time a specific AWS EC2 instance is updated. When I first apply the configuration, the script executes as expected, but subsequent updates to the instance (like changing the instance type) do not trigger the script to run again. Here is the relevant part of my Terraform configuration: ```hcl resource "aws_instance" "my_instance" { ami = "ami-0c55b159cbfafe01e" instance_type = "t2.micro" provisioner "local-exec" { command = "bash ./my-script.sh" } } ``` I expected that by changing the `instance_type` attribute, the local-exec provisioner would run again, but it seems that's not happening. After applying changes, I see the following output: ``` aws_instance.my_instance: Modifying... [id=i-0abcd1234efgh5678] aws_instance.my_instance: Still modifying... [id=i-0abcd1234efgh5678, 10s elapsed] aws_instance.my_instance: Modifications complete after 30s [id=i-0abcd1234efgh5678] ``` I also confirmed that the script `my-script.sh` has execution permissions (`chmod +x my-script.sh`). I've tried using `null_resource` with a `triggers` argument to force the execution, but that feels like a workaround rather than a solution. Here's an example of how I tried it with null_resource: ```hcl resource "null_resource" "update_script" { triggers = { instance_id = aws_instance.my_instance.id instance_type = aws_instance.my_instance.instance_type } provisioner "local-exec" { command = "bash ./my-script.sh" } } ``` But then I end up with two resources managing the script execution, which feels messy. I'm using Terraform version `1.2.0`. Is there a clean way to ensure that the local-exec provisioner runs on every update of the resource? What best practices should I follow here to avoid this issue? I recently upgraded to Hcl latest. I'm on Windows 10 using the latest version of Hcl. I appreciate any insights!