runway.env_mgr.tfenv module

Terraform version management.

runway.env_mgr.tfenv.download_tf_release(version: str, versions_dir: Path, command_suffix: str, tf_platform: Optional[str] = None, arch: Optional[str] = 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.

  • parser (Union[hcl, hcl2]) – Parser to use when loading files.

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

class runway.env_mgr.tfenv.TFEnvManager[source]

Bases: runway.env_mgr.EnvManager

Terraform version management.

Designed to be compatible with

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

Initialize class.

property backend: Dict[str, Any]

Backend config of the Terraform module.

property terraform_block: Dict[str, Any]

Collect Terraform configuration blocks from a Terraform module.

property version: Optional[runway.utils._version.Version]

Terraform version.

property version_file: Optional[Path]

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


Path to the Terraform version file.

get_min_required() str[source]

Get the defined minimum required version of Terraform.


The minimum required version as defined in the module.

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

Get Terraform version from a file.


file_path – Path to file that will be read.

install(version_requested: Optional[str] = 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.

set_version(version: str) None[source]

Set current version.

Clears cached values as needed.


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

classmethod get_version_from_executable(bin_path: Union[Path, str], *, cwd: Optional[Union[Path, str]] = None, env: Optional[Dict[str, str]] = None) Optional[Version][source]

Get Terraform version from an executable.

  • 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.

classmethod parse_version_string(version: str) runway.utils._version.Version[source]

Parse version string into a Version.


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

property bin: pathlib.Path

Path to the version binary.



property command_suffix: str

Return command suffix based on platform.system.

property env_dir: pathlib.Path

Return the directory used to store version binaries.

uninstall(version: Union[str, Version]) bool

Uninstall a version of the managed binary.


version – Version of binary to uninstall.


Whether a version of the binary was uninstalled or not.

property versions_dir: pathlib.Path

Return the directory used to store binary.

When first used, the existence of the directory is checked and it is created if needed.