{"id":50441232,"url":"https://github.com/langburd/set-tf-alias","last_synced_at":"2026-05-31T19:30:36.424Z","repository":{"id":352230703,"uuid":"1214362559","full_name":"langburd/set-tf-alias","owner":"langburd","description":"Portable bash/zsh library that auto-switches tf/tofu/terraform aliases based on .opentofu-version/.terraform-version files and tenv integration","archived":false,"fork":false,"pushed_at":"2026-04-27T09:05:12.000Z","size":118,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-27T11:07:22.851Z","etag":null,"topics":["opentofu","shell","terraform"],"latest_commit_sha":null,"homepage":"https://www.linkedin.com/posts/langburd_devops-terraform-opentofu-share-7453082282162081793-HVvQ/","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/langburd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-18T13:23:39.000Z","updated_at":"2026-04-27T09:07:09.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/langburd/set-tf-alias","commit_stats":null,"previous_names":["langburd/set-tf-alias"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/langburd/set-tf-alias","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/langburd%2Fset-tf-alias","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/langburd%2Fset-tf-alias/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/langburd%2Fset-tf-alias/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/langburd%2Fset-tf-alias/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/langburd","download_url":"https://codeload.github.com/langburd/set-tf-alias/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/langburd%2Fset-tf-alias/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33746506,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-31T02:00:06.040Z","response_time":95,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["opentofu","shell","terraform"],"created_at":"2026-05-31T19:30:35.468Z","updated_at":"2026-05-31T19:30:36.412Z","avatar_url":"https://github.com/langburd.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# set-tf-alias\n\nPortable bash/zsh shell library that auto-switches `tf`, `tofu`, and\n`terraform` aliases based on `.opentofu-version` / `.terraform-version` files\nand [`tenv`](https://tofuutils.github.io/tenv/) as the required version manager. Works on macOS\nand Linux under bash ≥ 4 and zsh ≥ 5.\n\n## What it does\n\nWhen you `cd` into a project, `set-tf-alias` walks up the directory tree\nlooking for `.opentofu-version` or `.terraform-version`. If it finds one, it\ninvokes `tenv` to install and activate the pinned version, and points `tf`,\n`tofu`, and `terraform` at the right binary. When no version file is present,\nit falls back to reading `.terraform.lock.hcl` for the provider registry,\nthen to the presence of `*.tofu` files in the current directory.\nRead more about the problem this solves on [LinkedIn](https://www.linkedin.com/posts/langburd_devops-terraform-opentofu-share-7453082282162081793-HVvQ/).\n\n## Demo\n\n```text\n$ cd my-opentofu-project\n✓ set_tf_alias: tofu 1.8.5 (via .opentofu-version)\n$ tf plan          # runs opentofu 1.8.5\n\n$ cd ../legacy-terraform-project\n✓ set_tf_alias: terraform 1.5.7 (via .terraform-version)\n$ tf plan          # runs terraform 1.5.7\n```\n\n## Aliases\n\nAll aliases point to whichever binary was detected (`terraform`, `tofu`, or the `tenv`-managed version).\n\n| Alias | Expands to |\n| --- | --- |\n| `tf` | `\u003cbin\u003e` |\n| `terraform` | `\u003cbin\u003e` |\n| `tofu` | `\u003cbin\u003e` |\n| `tfa` | `\u003cbin\u003e apply` |\n| `tfaa` | `\u003cbin\u003e apply -auto-approve` |\n| `tfat` | `\u003cbin\u003e apply -target` |\n| `tfc` | `\u003cbin\u003e console` |\n| `tfd` | `\u003cbin\u003e destroy` |\n| `tfdt` | `\u003cbin\u003e destroy -target` |\n| `tff` | `\u003cbin\u003e fmt` |\n| `tffr` | `\u003cbin\u003e fmt -recursive` |\n| `tfg` | `\u003cbin\u003e get` |\n| `tfi` | `\u003cbin\u003e init` |\n| `tfim` | `\u003cbin\u003e init -migrate-state` |\n| `tfir` | `\u003cbin\u003e init -reconfigure` |\n| `tfiu` | `\u003cbin\u003e init -upgrade` |\n| `tfo` | `\u003cbin\u003e output` |\n| `tfp` | `\u003cbin\u003e plan` |\n| `tfpsum` | `\u003cbin\u003e plan \\| grep -E '(will\\|must) be'` |\n| `tfpt` | `\u003cbin\u003e plan -target` |\n| `tfs` | `\u003cbin\u003e state` |\n| `tfsh` | `\u003cbin\u003e show` |\n| `tft` | `\u003cbin\u003e test` |\n| `tfv` | `\u003cbin\u003e validate` |\n| `tfw` | `\u003cbin\u003e workspace` |\n| `tfws` | `\u003cbin\u003e workspace select` |\n\n## Install\n\n### Homebrew (recommended)\n\n```bash\nbrew tap langburd/tap\nbrew install set-tf-alias\n```\n\nThen add this line to your `~/.zshrc` or `~/.bashrc`:\n\n```bash\nsource \"$(brew --prefix)/share/set-tf-alias/set-tf-alias.sh\"\n```\n\nBash users: ensure bash ≥ 4 with `brew install bash`. Apple's default bash 3.2\nis not supported.\n\n### `curl | bash`\n\n```bash\ncurl -fsSL https://github.com/langburd/set-tf-alias/releases/latest/download/install.sh | bash\n```\n\nThe installer downloads the library to `~/.local/share/set-tf-alias/set-tf-alias.sh`\nand appends a source line to your rc. It's idempotent — re-run it to upgrade.\n\nTo pin to a specific version: `STF_TAG=v0.1.2 bash \u003c(curl -fsSL ...)`\n\n### Manual\n\n```bash\ngit clone https://github.com/langburd/set-tf-alias.git ~/.local/share/set-tf-alias\necho 'source ~/.local/share/set-tf-alias/set-tf-alias.sh' \u003e\u003e ~/.zshrc\n```\n\n## Configuration\n\n| Variable | Default | Effect |\n| --- | --- | --- |\n| `SET_TF_ALIAS_AUTOHOOK` | `1` | Set to `0` to disable the `chpwd` / `PROMPT_COMMAND` hook AND the initial invocation. `set_tf_alias` remains defined so you can call it manually. |\n| `SET_TF_ALIAS_DEBUG` | `0` | Set to `1` to print detection steps to stderr. |\n\n## How detection works\n\n1. Walk up from `$PWD`. First `.opentofu-version` or `.terraform-version`\n   file wins.\n2. If no version file, check `.terraform.lock.hcl` in `$PWD`:\n   `registry.opentofu.org` → `tofu`.\n3. If no lockfile match, check for `*.tofu` files in `$PWD` → `tofu`.\n4. Otherwise, alias to the system `terraform` binary.\n\n## Requirements\n\n- bash ≥ 4 **or** zsh ≥ 5.\n- [`tenv`](https://tofuutils.github.io/tenv/) **required** as the\n  Terraform/OpenTofu version manager.\n\n## Troubleshooting\n\n```bash\nSET_TF_ALIAS_DEBUG=1 set_tf_alias\n```\n\nPaste the output in a GitHub issue.\n\n## Contributing\n\n```bash\ngit clone https://github.com/langburd/set-tf-alias.git\ncd set-tf-alias\npre-commit install \u0026\u0026 pre-commit install -t commit-msg\nbats test/bats/\n```\n\nOpen a PR against `main`. Bug reports and feature requests are welcome via\nGitHub Issues.\n\n**Releasing:** Releases are automated via release-please. Merge any PR to `main` with conventional commits (`feat:`, `fix:`, etc.) and release-please will open a Release PR bumping `version.txt` and `CHANGELOG.md`. Merging the Release PR creates the tag, which triggers the release workflow (GitHub Release + Homebrew tap PR). A `HOMEBREW_TAP_TOKEN` secret (PAT with `repo` scope on `langburd/homebrew-tap`) must be configured in Actions secrets.\n\n## License\n\nMIT. See [LICENSE](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flangburd%2Fset-tf-alias","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flangburd%2Fset-tf-alias","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flangburd%2Fset-tf-alias/lists"}