Welcome to the OpenTofu Remote State lab! In this tutorial, you’ll learn how to manage Terraform state locally and then migrate it to a remote S3-compatible backend using MinIO. We’ll walk through creating local state, switching variables, configuring S3 backend, and migrating your state seamlessly.Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.

1. Define a Local File Resource
Createmain.tf with a local_file resource that writes to a file based on a variable:
variables.tf:
| Variable | Type | Default | Description |
|---|---|---|---|
var.local_state | string | local | Filename when using local state |
var.remote_state | string | remote | Filename when using remote state |
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.
