OpenTofu and Terraform patterns for moved, import, and removed blocks, for_each, state secrets, and the lock file. Load before any edit to a .tf or .tfvars file, however small, and for HCL questions.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Opentofu Patterns?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/ku5ic-opentofu-patterns)
---
name: opentofu-patterns
description: OpenTofu and Terraform patterns for moved, import, and removed blocks, for_each, state secrets, and the lock file. Load before any edit to a .tf or .tfvars file, however small, and for HCL questions.
---
# OpenTofu patterns
Default assumption: OpenTofu 1.13, per the OpenTofu changelog. Most rules hold for Terraform too.
A row applies when `required_version` in the `terraform {}` block allows only releases at or above its version, for the CLI the project runs. A row marked OpenTofu is an OpenTofu release; its Terraform version, where one exists, is in the row.
## Reference files
Loading this skill isn't enough. Before your next edit, read the file of every row that matches it. The rules live in those files, and this one only points at them.
| Before | Read |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------- |
| Writing HCL, or raising `required_version` or the `tofu` CLI | [reference/upgrades.md](reference/upgrades.md) |
| Writing, changing, or reviewing OpenTofu or Terraform code | [reference/anti-patterns.md](reference/anti-patterns.md) |
| Writing variables, modules, provider requirements, a backend, the lock file, an `import`, `moved`, or `removed` block, or `depends_on`, or applying a plan | [reference/practices.md](reference/practices.md) |
| Running or wiring `fmt`, `validate`, TFLint, or Trivy | [reference/tooling.md](reference/tooling.md) |