{"id":14063945,"url":"https://github.com/stknohg/TerraformUtil","last_synced_at":"2025-07-29T17:30:59.062Z","repository":{"id":60170590,"uuid":"541151470","full_name":"stknohg/TerraformUtil","owner":"stknohg","description":"PowerShell utility functions for Terraform.","archived":false,"fork":false,"pushed_at":"2024-07-14T04:50:10.000Z","size":87,"stargazers_count":4,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-12-04T02:35:18.954Z","etag":null,"topics":["powershell","powershell-module","terraform"],"latest_commit_sha":null,"homepage":"","language":"PowerShell","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/stknohg.png","metadata":{"files":{"readme":"README-jp.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}},"created_at":"2022-09-25T11:42:03.000Z","updated_at":"2024-07-14T04:50:13.000Z","dependencies_parsed_at":"2024-07-14T05:37:21.958Z","dependency_job_id":"b47f74c6-b9e9-48e7-a613-a3d59b60d1bc","html_url":"https://github.com/stknohg/TerraformUtil","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/stknohg/TerraformUtil","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stknohg%2FTerraformUtil","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stknohg%2FTerraformUtil/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stknohg%2FTerraformUtil/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stknohg%2FTerraformUtil/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stknohg","download_url":"https://codeload.github.com/stknohg/TerraformUtil/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stknohg%2FTerraformUtil/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267726742,"owners_count":24134901,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-29T02:00:12.549Z","response_time":2574,"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":["powershell","powershell-module","terraform"],"created_at":"2024-08-13T07:03:35.383Z","updated_at":"2025-07-29T17:30:58.781Z","avatar_url":"https://github.com/stknohg.png","language":"PowerShell","funding_links":[],"categories":["PowerShell"],"sub_categories":[],"readme":"# TerraformUtil\n\n![build](https://github.com/stknohg/TerraformUtil/workflows/build/badge.svg)\n\nPowerShell utility functions for [Terraform](https://www.terraform.io/).  \n\n* [English](./README.md)\n\n## 事前要求\n\n* PowerShell 7 以降のバージョンに対応しています\n\n## インストール方法\n\n[PowerShell gallery](https://www.powershellgallery.com/packages/TerraformUtil/)からインストールできます。  \n\n```powershell\nInstall-Module -Name TerraformUtil -Force\n```\n\n## TFAlias Functions\n\n\u003e [!CAUTION]  \n\u003e `tenv`が非常に良いツールだったので将来的にこの機能は削除する予定です。  \n\u003e * [tofuutils / tenv](https://github.com/tofuutils/tenv)\n\nこのモジュールでは[tfenv](https://github.com/tfutils/tfenv)と同等の機能を提供しています。  \n\n### 比較表\n\n|tfenv|TerraformUtil|notes|\n|----|----|----|\n|tfenv install|Set-TFAlias|Set-TFAliasでは自動的にTerraformをインストールします|\n|tfenv use|Set-TFAlias||\n|tfenv uninstall|Uninstall-TFAlias||\n|tfenv list|Get-TFInstalledAlias||\n|tfenv list-remote|Find-TFVersion|Find-TFReleaseも利用可能です|\n|tfenv version-name|-|代わりに`Get-TFInstalledAlias -Current`を利用可能です|\n|tfenv init|-|`Set-TFAlias -Initialize`が近い機能となります|\n|tfenv pin|Set-TFAlias||\n\n### Set-TFAlias\n\ntfenvの様に`terraform`コマンドへのエイリアスを設定します。    \n\n```powershell\n# 初期化処理と、最新バージョンのTerraformをダウンロードします\nC:\\ \u003e Set-TFAlias -Initialize\n\n# 最新バージョンのTerraformに切り替えます\nC:\\ \u003e Set-TFAlias -Latest\nC:\\ \u003e terraform version\nTerraform vX.Y.Z\n\n# Terraform v.1.2.3に切り替えます\nC:\\ \u003e Set-TFAlias -Version 1.2.3  \nC:\\ \u003e terraform version\nTerraform v1.2.3\n\n# Terraformのバイナリはshim経由で実行されます\nC:\\ \u003e Get-Command -Name 'terraform' | Select-Object CommandType, Name, Definition\n\nCommandType Name      Definition\n----------- ----      ----------\n      Alias terraform C:\\Users\\stknohg\\.tfalias\\bin\\terraform.ps1\n```\n\n\u003e **Note**  \n\u003e 永続化する場合は `Set-TFAlias -Initialize` を [$PROFILE](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles) に記述してください\n\n#### .terraform-version ファイルのサポート\n\ntfenv同様Set-TFAliasでは[.terraform-version](https://github.com/tfutils/tfenv#terraform-version-file)ファイルをサポートしますが `min-required` と `latest-allowed` の扱いが異なります。    \n\n* [min-required \u0026 latest-allowed](https://github.com/tfutils/tfenv#min-required--latest-allowed)\n\n```terraform\n// min-required\n\n// tfenvは 0.12.3 と判定しますが、Set-TFAliasは 0.10.0 と判定します\nterraform {\n  required_version  = \"\u003c0.12.3, \u003e= 0.10.0\"\n}\n```\n\n```terraform\n// latest-allowed\n\n// tfenvだとエラーになりますが、Set-TFAliasは 0.12.2 と判定します\nterraform {\n  required_version  = \"\u003c0.12.3, \u003e= 0.10.0\"\n}\n```\n\n`Set-TFAlias -Pin`コマンドを使うと`.terraform-version`ファイルにピン止めできます。   \n\n```powershell\n# .terraform-version ファイルにピン止めできます\nC:\\temp \u003e Set-TFAlias -Pin\nPinned version by writing \"1.2.3\" to C:\\temp\\.terraform-version\n```\n\n### Get-TFInstalledAlias\n\nインストール済みの`terraform`エイリアスを取得します。  \n\n```powershell\n# 全てのインストール済みTerraformを取得\nC:\\ \u003e Get-TFInstalledAlias\n\nCurrent Version   Path\n------- -------   ----\n  False X.Y.Z     C:\\Users\\stknohg\\.tfalias\\terraform\\X.Y.Z\\terraform.exe\n   True 1.2.3     C:\\Users\\stknohg\\.tfalias\\terraform\\1.2.3\\terraform.exe\n```\n\n### Uninstall-TFAlias\n\n`terraform`エイリアスをアンインストールします。  \n\n```powershell\n# Terraform v1.2.3をアンインストール\nC:\\ \u003e Uninstall-TFAlias -Version 1.2.3\nUninstall Terraform v1.2.3\n```\n\n## TFAlias for Command Prompt\n\n\u003e **Note**  \n\u003e これは試験的な機能であり、非サポートです\n\n* [[Experimental] TFAlias for Command Prompt](./TFAliasForCmd.md)\n\n## Other Functions\n\n### Register-TFArgumentCompleter\n\n`terraform`コマンドに対する入力補完を登録します。  \n\n```powershell\n# auto-completerの登録\nRegister-TFArgumentCompleter\n```\n\n### UnRegister-TFArgumentCompleter\n\n`terraform`コマンドに対する入力補完を解除します。  \n\n```powershell\n# auto-completerの解除\nUnRegister-TFArgumentCompleter\n```\n\n### Find-TFRelease\n\n[Hashicorp Releases API](https://releases.hashicorp.com/docs/api/v1/#operation/listReleasesV1)を使いTerraformのリリース情報を取得します。  \n\n\u003e **Note**  \n\u003e 現時点ではページネーションを実装する予定はありません\n\n```powershell\n# 最新バージョンのリリース情報を取得\nC:\\ \u003e Find-TFRelease -Latest\n\nVersion PreRelease State     Created              Updated\n------- ---------- -----     -------              -------\n1.3.2   False      supported 10/6/2022 4:57:24 PM 10/6/2022 4:57:24 PM\n```\n\n### Find-TFVersion\n\n`tfenv list-remote`コマンドと同様に `https://releases.hashicorp.com/terraform` をスクレイピングしてTerraformのバージョンリストを取得します。  \n\n\u003e **Note**  \n\u003e オリジンへのアクセスを制限するため実行結果は10分キャッシュされます  \n\n```powershell\n# 全バージョン取得 (デフォルトで降順)\nC:\\ \u003e Find-TFVersion\n\nMajor  Minor  Patch  PreReleaseLabel BuildLabel\n-----  -----  -----  --------------- ----------\n1      3      2\n1      3      1\n1      3      0\n# ... 中略 ...\n0      2      0\n0      1      1\n0      1      0\n\n# -Filter スクリプトブロックを使用可能\nC:\\ \u003e Find-TFVersion -Filter { $_ -lt '1.0.0' -and (-not $_.PreReleaseLabel) } -Take 1\n\nMajor  Minor  Patch  PreReleaseLabel BuildLabel\n-----  -----  -----  --------------- ----------\n0      15     5\n\n# Find-TFReleaseへパイプ可能\nC:\\ \u003e Find-TFVersion -Filter { $_ -lt '1.0.0' -and (-not $_.PreReleaseLabel) } -Take 1 | Find-TFRelease\n\nVersion PreRelease State     Created             Updated\n------- ---------- -----     -------             -------\n0.15.5  False      supported 6/2/2021 6:01:19 PM 6/2/2021 6:01:19 PM\n```\n\n### Save-TFBinary\n\n特定バージョンのTerraformバイナリファイル(`terraform.exe`または`terraform`)を保存します。  \n\n```powershell\n# 最新バージョンのバイナリを \"C:\\hashicorp\\terraform\" フォルダに保存\nSave-TFBinary -Latest -DestinationPath C:\\hashicorp\\terraform\n\n# Ver.1.2.9 のバイナリを \"C:\\hashicorp\\terraform\" フォルダに保存\nSave-TFBinary -Version 1.2.9 -DestinationPath C:\\hashicorp\\terraform\n```\n\n### Save-TFSecBinary\n\n特定バージョンの[Terraform securiy scanner](https://github.com/aquasecurity/tfsec)バイナリファイル(`tfsec.exe`または`tfsec`)を保存します。  \n\n```powershell\n# 最新バージョンのバイナリを \"C:\\hashicorp\\terraform\" フォルダに保存\nSave-TFSecBinary -Latest -DestinationPath C:\\hashicorp\\terraform\n\n# Ver.1.23.3 のバイナリを \"C:\\hashicorp\\terraform\" フォルダに保存\nSave-TFSecBinary -Version 1.23.3 -DestinationPath C:\\hashicorp\\terraform\n```\n\n### Save-TFLinterBinary\n\n特定バージョンの[Linter](https://github.com/terraform-linters/tflint)バイナリファイル(`tflint.exe`または`tflint`)を保存します。  \n\n```powershell\n# 最新バージョンのバイナリを \"C:\\hashicorp\\terraform\" フォルダに保存\nSave-TFLinterBinary -Latest -DestinationPath C:\\hashicorp\\terraform\n\n# Ver.0.40.0 のバイナリを \"C:\\hashicorp\\terraform\" フォルダに保存\nSave-TFLinterBinary -Version 0.40.0 -DestinationPath C:\\hashicorp\\terraform\n```\n\n### Write-TFLinterHCL\n\n`.tflint.hcl`ファイル用の基本的な設定内容を出力します。  \n`-Plugin`パラメーターの値は [Terraform](https://github.com/terraform-linters/tflint), [AWS](https://github.com/terraform-linters/tflint-ruleset-aws),[AzureRM](https://github.com/terraform-linters/tflint-ruleset-azurerm), [Google](https://github.com/terraform-linters/tflint-ruleset-google) がサポートされています。  \n\n```powershell\n# terraform-provider-aws 向けの設定を出力\nC:\\Sample \u003e Write-TFLinterHCL -Plugin AWS\nplugin \"aws\" {\n  enabled = true\n  version = \"0.17.1\" # 最新バージョンを自動的に設定\n  source  = \"github.com/terraform-linters/tflint-ruleset-aws\"\n}\n\n# -Save パラメーターを使うと .tflint.hcl ファイルに内容を保存可能\nC:\\Sample \u003e Write-TFLinterHCL -Plugin AWS -Save\nSave configuration to \".tflint.hcl\".\n\n# もちろんリダイレクトを使って保存しても構いません\nC:\\Sample \u003e Write-TFLinterHCL -Plugin AWS \u003e '.tflint.hcl'\n```\n\n## アンインストール方法\n\n```powershell\n# 手順 1. モジュールをアンインストールします\nUninstall-Module TerraformUtil -Force\n\n# 手順 2. \"terraform\"エイリアスを削除します\nRemove-Alias terraform\n\n# 手順 3. \"$HOME\\.tfenv\"ディレクトリを削除します\nRemove-Item -LiteralPath (Join-Path $HOME '.tfalias') -Recurse\n```\n\n## ライセンス\n\n* [MIT](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstknohg%2FTerraformUtil","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstknohg%2FTerraformUtil","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstknohg%2FTerraformUtil/lists"}