runway.env_mgr.tfenv module

Terraform version management.

class runway.env_mgr.tfenv.TFEnvManager[source]

Bases: EnvManager

Terraform version management.

Designed to be compatible with https://github.com/tfutils/tfenv.

__init__(path: Path | None = None) None[source]

Initialize class.

property backend: dict[str, Any]

Backend config of the Terraform module.

get_min_required() str[source]

Get the defined minimum required version of Terraform.

Returns:

The minimum required version as defined in the module.

classmethod get_version_from_executable(bin_path: Path | str, *, cwd: Path | str | None = None, env: dict[str, str] | None = None) Version | None[source]

Get Terraform version from an executable.

Parameters:
  • bin_path – Path to the Terraform binary to retrieve the version from.

  • cwd – Current working directory to use when calling the executable.

  • env – Environment variable overrides.

get_version_from_file(file_path: Path | None = None) str | None[source]

Get Terraform version from a file.

Parameters:

file_path – Path to file that will be read.

install(version_requested: str | None = None) str[source]

Ensure Terraform is available.

list_installed() Generator[Path, None, None][source]

List installed versions of Terraform.

Only lists versions of Terraform that have been installed by an instance if this class or by tfenv.

classmethod parse_version_string(version: str) Version[source]

Parse version string into a Version.

Parameters:

version – Version string to parse. Must be in the format of <major>.<minor>.<patch> with an optional -<prerelease>.

set_version(version: str) None[source]

Set current version.

Clears cached values as needed.

Parameters:

version – Version string. Must be in the format of <major>.<minor>.<patch> with an optional -<prerelease>.

property terraform_block: dict[str, Any]

Collect Terraform configuration blocks from a Terraform module.

property version: Version | None

Terraform version.

property version_file: Path | None

Find and return a “.terraform-version” file if one is present.

Returns:

Path to the Terraform version file.

runway.env_mgr.tfenv.download_tf_release(version: str, versions_dir: Path, command_suffix: str, tf_platform: str | None = None, arch: str | None = None) None[source]

Download Terraform archive and return path to it.

runway.env_mgr.tfenv.get_available_tf_versions(include_prerelease: bool = False) list[str][source]

Return available Terraform versions.

runway.env_mgr.tfenv.get_latest_tf_version(include_prerelease: bool = False) str[source]

Return latest Terraform version.

runway.env_mgr.tfenv.load_terraform_module(parser: ModuleType, path: Path) dict[str, Any][source]

Load all Terraform files in a module into one dict.

Parameters:
  • parser – Parser to use when loading files.

  • path – Terraform module path. All Terraform files in the path will be loaded.