I wrote an advanced tutorial for HashiCorp on safely editing Terraform state files using the Terraform Cloud API and how to fix corrupted state without making things worse.
State files get corrupted from partial applies, bad imports, or other mishaps. When it happens in production, you need to know how to fix it with minimal delay.
I provided complete shell scripts for downloading state, creating encrypted payloads, and uploading via API. The guide is complete with steps on proper versioning, MD5 checksums, and all the safety checks you actually need.