feat(terraform): support opentofu for terraform version detection (#6910)

Support OpenTofu

This is a revitalization of https://github.com/starship/starship/pull/6072

Co-authored-by: Bojan Rajkovic <brajkovic@coderinserepeat.com>
This commit is contained in:
Joey Marianer
2025-09-06 10:14:17 -07:00
committed by GitHub
parent 95bf53f6b9
commit ef7d8bd442
4 changed files with 66 additions and 17 deletions
+15 -13
View File
@@ -4600,9 +4600,10 @@ format = 'via [🏎 $version](red bold)'
## Terraform
The `terraform` module shows the currently selected [Terraform workspace](https://www.terraform.io/docs/language/state/workspaces.html) and version.
It supports both Hashicorp Terraform and OpenTofu for version detection.
> [!TIP]
> By default the Terraform version is not shown, since this is slow for current versions of Terraform when a lot of plugins are in use.
> By default the Terraform/OpenTofu version is not shown, since this is slow for current versions when a lot of plugins are in use.
> If you still want to enable it, [follow the example shown below](#with-terraform-version).
By default the module will be shown if any of the following conditions are met:
@@ -4612,16 +4613,17 @@ By default the module will be shown if any of the following conditions are met:
### Options
| Option | Default | Description |
| ------------------- | ------------------------------------ | ------------------------------------------------------------------------- |
| `format` | `'via [$symbol$workspace]($style) '` | The format string for the module. |
| `version_format` | `'v${raw}'` | The version format. Available vars are `raw`, `major`, `minor`, & `patch` |
| `symbol` | `'💠'` | A format string shown before the terraform workspace. |
| `detect_extensions` | `['tf', 'tfplan', 'tfstate']` | Which extensions should trigger this module. |
| `detect_files` | `[]` | Which filenames should trigger this module. |
| `detect_folders` | `['.terraform']` | Which folders should trigger this module. |
| `style` | `'bold 105'` | The style for the module. |
| `disabled` | `false` | Disables the `terraform` module. |
| Option | Default | Description |
| ------------------- | ------------------------------------------------------- | ------------------------------------------------------------------------- |
| `format` | `'via [$symbol$workspace]($style) '` | The format string for the module. |
| `version_format` | `'v${raw}'` | The version format. Available vars are `raw`, `major`, `minor`, & `patch` |
| `symbol` | `'💠'` | A format string shown before the terraform workspace. |
| `detect_extensions` | `['tf', 'tfplan', 'tfstate']` | Which extensions should trigger this module. |
| `detect_files` | `[]` | Which filenames should trigger this module. |
| `detect_folders` | `['.terraform']` | Which folders should trigger this module. |
| `style` | `'bold 105'` | The style for the module. |
| `disabled` | `false` | Disables the `terraform` module. |
| `commands` | `[ [ 'terraform', 'version' ], [ 'tofu', 'version' ] ]` | How to detect what the Terraform version is. |
### Variables
@@ -4642,7 +4644,7 @@ By default the module will be shown if any of the following conditions are met:
# ~/.config/starship.toml
[terraform]
format = '[🏎💨 $version$workspace]($style) '
format = 'via [$symbol$version $workspace]($style) '
```
#### Without Terraform version
@@ -4651,7 +4653,7 @@ format = '[🏎💨 $version$workspace]($style) '
# ~/.config/starship.toml
[terraform]
format = '[🏎💨 $workspace]($style) '
format = 'via [$symbol$workspace]($style) '
```
## Time