While modifying Terraform code and testing my changes, the tfstate file occasionally (often) gets locked - at which point I can no longer run any Terraform commands. From that point on, all I get is “Error: Failed to load state: open .terraform\terraform.tfstate: Access is denied.” The only solution I’ve found is to reboot the machine, at which point I can delete the tfstate file and continue on my work. But when this happens every 15-30 mins or so, it’s getting to be a big problem with my workflow.
I’m using Windows 10 20H2 with VSCode as my editor, PowerShell as my execution environment, and Terraform 0.15.3 - and it happens whether or not I’m running as local Admin. I can see the tfstate file exists, it’s 2KB, but I have no permissions to it - I can’t open it, read it, delete it, or even take ownership of it. Running Process Explorer, it doesn’t find any running processes with a lock on the file. So I’m baffled about what could be locking the file so that even Terraform can’t read it. Any ideas?