Back to Oh My Posh

Terraform Context

website/docs/segments/cli/terraform.mdx

29.25.12.4 KB
Original Source

What

Display the currently active Terraform Workspace name.

Sample Configuration

import Config from "@site/src/components/Config.js";

<Config data={{ type: "terraform", style: "powerline", powerline_symbol: "\uE0B0", foreground: "#000000", background: "#ebcc34", template: " \ue69a {{.WorkspaceName}}", }} />

Options

NameTypeDefaultDescription
fetch_versionbooleanfalsefetch the version information, see Version detection for the sources and their priority
commandstringterraformthe command(s) to run, allows support for tofu

Version detection

When fetch_version is enabled, the version is resolved from the first source that yields a value, in this order:

  1. the tenv environment variable — TFENV_TERRAFORM_VERSION (or TOFUENV_TOFU_VERSION when command is tofu)
  2. the tenv version file — .terraform-version (or .opentofu-version when command is tofu)
  3. the required_version declared in versions.tf or main.tf
  4. the terraform_version stored in terraform.tfstate

The tenv sources let the segment show the pinned version even when you don't use main.tf / versions.tf. The environment variable and version file are only used to read the version; a project file (a .terraform folder or one of the files above) is still required for the segment to activate.

Template (info)

:::note default template

template
 {{ .WorkspaceName }}{{ if .Version }} {{ .Version }}{{ end }}

:::

Properties

NameTypeDescription
.WorkspaceNamestringis the current workspace name
.Versionstringterraform version (set fetch_version to true)