@stuart-c Just to clarify on my requirement. What I want to do in local-exec is download some files and run a bunch of commands. So in this case it’s not just one file I want created.
I want null_resource to run always if a given file doesn’t exist.
Unfortunately what you are doing here (using Terraform to manage local files outside of the current working directory) is pretty unusual and not really in Terraform’s intended scope, so there aren’t really good facilities for doing it built into the Terraform language.
I expect there are ways to make it work, since ultimately a Terraform configuration is arbitrary code that can (with the help of providers) be convinced to do just about anything that a computer can typically do, but I don’t have a direct answer to your question ready to go.
Instead, I might suggest looking for a different approach where your Terraform configuration can avoid modifying the local filesystem outside of its scope. I don’t really know what to suggest since I don’t have any information on the real underlying use-case behind this solution you’ve tried, but I’d be happy to try to make some suggestions if you’d be willing to share some more details about what your underlying goal is, independent of any particular Terraform-based solution to that goal.