هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
$ مستخدم عادي# بصلاحية root (أو مع sudo)
Know it before you install
OpenTofu = Terraform's workflow (init, plan, apply) + an open license + extra features. Providers come from registry.opentofu.org (it mirrors the common providers). Choose one tool per project — do not mix terraform and tofu on the same state.
| Item | Value |
|---|---|
| Package | tofu (repository packages.opentofu.org) |
| Program | /usr/bin/tofu |
| Project files | *.tf (and *.tofu for OpenTofu-only code), .terraform.lock.hcl |
| CLI settings | ~/.tofurc (or ~/.terraformrc) |
| Extra features | state and plan encryption, early variable evaluation, provider for_each, -exclude |
Install on RHEL and Ubuntu
The official installer script adds the right repository for your system. Download it, read it, then run it with your package type:
curl --proto '=https' --tlsv1.2 -fsSL https://get.opentofu.org/install-opentofu.sh -o install-opentofu.sh
less install-opentofu.sh
chmod +x install-opentofu.sh
./install-opentofu.sh --install-method rpm
./install-opentofu.sh --install-method deb
tofu version
OpenTofu v1.10.6
on linux_amd64(Use rpm on RHEL/Fedora, deb on Ubuntu/Debian.) After that, dnf upgrade / apt upgrade keeps tofu updated.
First configuration: a project with encrypted state
Pin the versions, as with Terraform:
terraform {
required_version = ">= 1.10"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 6.0"
}
}
}State encryption — the state often holds passwords. OpenTofu can encrypt state and plan files itself (here with AWS KMS; for labs a passphrase also works):
terraform {
encryption {
key_provider "aws_kms" "main" {
kms_key_id = "alias/tofu-state"
region = "eu-central-1"
key_spec = "AES_256"
}
method "aes_gcm" "main" {
keys = key_provider.aws_kms.main
}
state {
method = method.aes_gcm.main
enforced = true
}
plan {
method = method.aes_gcm.main
enforced = true
}
}
}Plus a remote backend with locking (same as Terraform, for example S3 with use_lockfile = true) and the .gitignore (.terraform/, *.tfstate*, *.tfvars).
| Setting | Why |
|---|---|
encryption with KMS | State and plans are encrypted before they reach the backend; only people with the KMS key can read them. |
enforced = true | OpenTofu refuses to write unencrypted state by mistake. |
| Pinned versions + lock file | Same providers on every laptop and in CI. |
Migrate a Terraform project
Do it on a clean state: no pending changes, everyone stopped working on it.
terraform plan
No changes. Your infrastructure matches the configuration.
cp terraform.tfstate terraform.tfstate.backup-before-tofu
tofu init -upgrade
tofu plan
No changes. Your infrastructure matches the configuration.(With a remote backend, make a copy of the state file in the bucket first.) If tofu plan shows no changes, the migration is done — use only tofu from now on, in CI too. Check the OpenTofu migration notes for your Terraform version (state from very new Terraform versions may need the matching OpenTofu version).
Daily use: the commands and the real uses
tofu plan -out=tfplan
tofu show tfplan
tofu apply tfplan
tofu state list
tofu output -json
tofu plan -exclude=module.legacy
tofu import aws_s3_bucket.logs acme-logs
tofu providers lock -platform=linux_amd64 -platform=darwin_arm64
tofu testReal uses at work:
- The same IaC work as Terraform, with an open license (important for some companies and products).
- Encrypted state without extra tools.
tofu testfor module tests; providerfor_eachfor many regions or accounts.
Make it safe
Security checklist:
- State encryption (
enforced = true) and a private, versioned backend with locking. - No secrets in
.tfor committed.tfvars;sensitive = trueon secret variables and outputs. - Short-lived cloud credentials (SSO, OIDC in CI).
- Pin OpenTofu and provider versions; review every plan.
- Scan the code with
trivy config .orcheckov. - Keep the KMS key and its permissions safe — losing it means losing the state.
Update and remove
Fix common problems
| Problem | Cause | Fix |
|---|---|---|
Failed to query available provider packages | Provider not found in the OpenTofu registry or no network. | Check the provider name; network to registry.opentofu.org. |
| State lock error | Another run or a crashed run. | Wait, or tofu force-unlock LOCK_ID when the run is really dead. |
encryption … key provider error | No access to the KMS key. | Check your cloud login and the KMS key policy. |
| State can not be read after switching tools | State written by a newer Terraform version. | Use a matching OpenTofu version; restore the backup; read the migration notes. |
Unsupported OpenTofu Core version | required_version does not match. | Install the right version or change the constraint. |
CI still runs terraform | Old pipeline. | Change the image and commands to tofu; one tool per state. |
Next steps
- Command page: tofu, Command page: terraform.
- The same workflow in depth: Install and set up Terraform, Terraform summary.
- At work: OpenTofu — the open-source Terraform. Many environments: Terragrunt.
1How do you know a Terraform → OpenTofu migration worked?
2What does enforced = true in the state encryption block do?
OpenTofu refuses to write the state without encryption.