Still encountering the same issue with terraform state refresh

Unfortunately I had already tried the snippet shared by @apparentlymart in 24899 and had the same issue. The file function was failing earlier and hiding the issue. Though, in the documentation of the function, it clearly states it only works for static configuration and I was using incorrectly.

In the below snippet, the first apply goes smoothly.
In a second apply with the file present, works out.
In a third apply, without the file present, it fails when refreshing the data.local_file state because the file is not present.
I was expecting terraform not to load the file content when there are no dependencies changes. Is this intended?


data "local_file" "generated_template" {
  filename = "${path.module}/${null_resource.file.triggers.timestamp}"
}

data "template_file" "result" {
  template = data.local_file.generated_template.content
  vars = {
    id = null_resource.file.id
  }
}

resource "null_resource" "file" {
  provisioner "local-exec" {
    command = "echo test > $PATH/$NAME"
    environment = {
      PATH = path.module
      NAME = self.triggers.timestamp
    }
  }
  triggers = {
    timestamp = time_rotating.test.unix
  }
}

resource "time_rotating" "test" {
  rotation_minutes = 1
}

output "test" {
  value = data.template_file.result.rendered
}