- Robust state encryption to secure your plan and state files at rest.
- The
removedblock to drop resources from your state without tearing down real infrastructure.
1. State Encryption
OpenTofu v1.7.0 adds native support for encrypting both local and remote state and plan files. You can also leverage this capability when reading remote state via a Terraform Remote State data source.1.1. How It Works
| Component | Description |
|---|---|
| key_provider | Derives a strong key from a passphrase (PBKDF2) |
| method | Defines the encryption algorithm (AES-GCM) |
| state | Configures how encrypted/unencrypted state is read and written |
Using state encryption requires OpenTofu v1.7.0 or later and support from your chosen backend.
1.2. Enabling Encryption on an Existing State
- Create a backup of your current
terraform.tfstate. - Update your configuration:
- Derives an AES-GCM key from your passphrase.
- Encrypts new state and plan files.
- Uses
fallbackto read existing unencrypted state during the migration.
After migration, your state and plan files are unrecoverable without the correct passphrase. Store it securely.
1.3. Migrating Back to an Unencrypted State
To revert to unencrypted state files:method in the state block, OpenTofu writes future state files unencrypted while still decrypting the current state.
2. Removing Resources Without Destruction
Theremoved block lets you forget resources from your state without destroying the actual infrastructure, ideal for drift repair or state cleanup.
2.1. Create a Sample Resource
Define and apply a simple file resource:test.txt on disk.
2.2. Drop the Resource from State
- Comment out or delete the
local_fileblock. - Add a
removedblock in your configuration:
- Preview the change:
local_file.test is removed from the state but will not delete test.txt.
The
removed block only affects your state file. It does not alter real-world resources.