I have a question on the behavior of terraform refresh when you've lost the tfstate files and I am looking to understand the expected behavior. Disclaimer right now i'm seeing this in a custom provider I am working on, so it might just be my code.
I created an object using a terraform file and then I manually deleted the tfstate and tfstate.backup files, to simulate loosing it, or someone else creating a different tfstate file, and trying to apply it.
What I have found is that
1. I need to run terraform plan first to recreate a tfstate file.
2. After that running a terraform refresh does not update the tfstate file based on what is seen live. I've adding logging the the Read operation in my resource to log when the function is entered and I don't see any logs showing the Read function being entered.
3. If I run terraform apply it will try and apply it and fail because the object already exists. After this terraform refresh seems to update the state in the tfstate files and I see a log message for the Read function being entered.
So from testing it appears that terraform refresh will not try and update the tfstate files, unless the tf file has been applied first, successfully or not.
I can see the need to run terraform plan first, but it seems that after that I should be able to run a terraform refresh to sync the data with the live environment.