
1. Define a Local File Resource
Createmain.tf with a local_file resource that writes to a file based on a variable:
variables.tf:
Initialize and review:
2. Inspect the Local State Output
Afterapply, view the generated file:
3. Set Up MinIO and Identify the Bucket
We’ll use MinIO as our S3-compatible object store. In your browser’s MinIO console, log in with:- Access Key:
foo - Secret Key:
barbarbar
remote-state bucket under Object Browser.
4. Switch to the Remote State Variable
Editmain.tf to use var.remote_state:
/root/local and creates /root/remote.
5. Configure the S3 Backend
Createterraform.tf with the S3 backend block:
When using MinIO, add these settings under the
s3 backend:tofu init yet.
6. Initialize the Backend and Migrate State
If you try to apply, you’ll see:Deleting the local
terraform.tfstate is irreversible. Ensure the remote copy is present before removal.7. Verify Remote State in MinIO
Go back to the MinIO console and open theremote-state bucket. You should see terraform.tfstate uploaded—confirming your remote backend is working.
