How do you migrate from local state to a new remote backend?
Answer
Provision backend resources (for example an S3 bucket with versioning and a DynamoDB table) from a separate bootstrap configuration.
Add the backend block to your Terraform configuration and run
terraform init -migrate-state.Verify the migration with
terraform state listorterraform state pulland keep a secure backup of the previous file.Remove or archive the local
terraform.tfstateonly after confirming new plans operate against the remote backend.