How do you migrate from Terraform to OpenTofu in production?
AdvancedProductionRefactoring, Migration and Drift
Answer
Pin and match the current Terraform version's feature set, back up all state, install tofu in a branch pipeline, run tofu init and tofu plan for every stack and require empty plans. Roll out stack by stack, since once OpenTofu writes state the Terraform CLI may refuse to read newer formats. Keep a documented rollback (state backup plus Terraform binary) and check any providers or modules sourced only from HCP.
More on Refactoring, Migration and Drift
What is your workflow for refactoring Terraform safely?IntermediateHow do you rename a resource inside a shared module without breaking consumers?AdvancedHow do you split one state into two without downtime?AdvancedHow do you merge two states?IntermediateHow do you import a large existing environment efficiently?IntermediateHow do you upgrade a major version of the AWS provider?Advanced