Skip to content

ibm

wrknv.managers.tf.ibm

IBM Terraform Tool Manager for wrknv

Manages IBM Terraform (formerly HashiCorp Terraform) versions for development environment.

Classes

IbmTfVariant

IbmTfVariant(config: WorkenvConfig | None = None)

Bases: TfManager

IBM Terraform variant - manages IBM Terraform (formerly HashiCorp Terraform) versions using HashiCorp's releases API.

Source code in wrknv/managers/tf/base.py
def __init__(self, config: WorkenvConfig | None = None) -> None:
    super().__init__(config)
    # Override install path to use tf versions directory
    self.install_path = pathlib.Path("~/.terraform.versions").expanduser()
    self.install_path.mkdir(parents=True, exist_ok=True)

    # Get workenv bin directory for copying active binaries
    self.workenv_bin_dir = get_workenv_bin_dir(config)

    # Metadata manager
    self.metadata_manager = TfMetadataManager(self.install_path, self.tool_name)
    self.metadata_manager.load_metadata()

    # Expose metadata for backward compatibility
    self.metadata = self.metadata_manager.metadata
    self.metadata_file = self.metadata_manager.metadata_file
Functions
get_available_versions
get_available_versions() -> list[str]

Get available IBM Terraform versions from HashiCorp releases API.

Source code in wrknv/managers/tf/ibm.py
def get_available_versions(self) -> list[str]:
    """Get available IBM Terraform versions from HashiCorp releases API."""
    try:
        # Use custom mirror if configured
        mirror_url = self.config.get_setting(
            "terraform_mirror", "https://releases.hashicorp.com/terraform"
        )
        api_url = f"{mirror_url.rstrip('/')}/index.json"

        logger.debug(f"Fetching IBM Terraform versions from {api_url}")

        response = get(api_url)
        data = response.json()

        versions = []
        for version_info in data.get("versions", {}).values():
            version = version_info.get("version")
            if version and not self._is_prerelease(version):
                versions.append(version)

        # Sort versions in descending order (latest first)
        versions.sort(key=version_sort_key, reverse=True)

        logger.debug(f"Found {len(versions)} IBM Terraform versions")
        # Log the first few versions to debug
        if versions:
            logger.debug(f"Latest versions: {versions[:5]}")

        return versions

    except Exception as e:
        raise ToolManagerError(f"Failed to fetch IBM Terraform versions: {e}") from e
get_checksum_url
get_checksum_url(version: str) -> str | None

Get checksum URL for IBM Terraform version.

Source code in wrknv/managers/tf/ibm.py
def get_checksum_url(self, version: str) -> str | None:
    """Get checksum URL for IBM Terraform version."""
    mirror_url = self.config.get_setting("terraform_mirror", "https://releases.hashicorp.com/terraform")
    return f"{mirror_url.rstrip('/')}/{version}/terraform_{version}_SHA256SUMS"
get_download_url
get_download_url(version: str) -> str

Get download URL for IBM Terraform version.

Source code in wrknv/managers/tf/ibm.py
def get_download_url(self, version: str) -> str:
    """Get download URL for IBM Terraform version."""
    platform_info = self.get_platform_info()
    os_name = platform_info["os"]
    arch = platform_info["arch"]

    # Use custom mirror if configured
    mirror_url = self.config.get_setting("terraform_mirror", "https://releases.hashicorp.com/terraform")

    return f"{mirror_url.rstrip('/')}/{version}/terraform_{version}_{os_name}_{arch}.zip"
get_harness_compatibility
get_harness_compatibility() -> dict

Get compatibility information for development tools.

Source code in wrknv/managers/tf/ibm.py
def get_harness_compatibility(self) -> dict:
    """Get compatibility information for development tools."""
    version = self.get_installed_version()
    if not version:
        return {"status": "not_installed"}

    # Check compatibility with development tools
    compatibility = {
        "status": "compatible",
        "version": version,
        "harness": {
            "go.cty": self._check_cty_compatibility(version),
            "go.wire": self._check_wire_compatibility(version),
            "conformance": self._check_conformance_compatibility(version),
        },
    }

    return compatibility
verify_installation
verify_installation(version: str) -> bool

Verify that IBM Terraform installation works and version matches.

Source code in wrknv/managers/tf/ibm.py
def verify_installation(self, version: str) -> bool:
    """Verify that IBM Terraform installation works and version matches."""
    binary_path = self.get_binary_path(version)
    if not binary_path.exists():
        logger.error(f"IBM Terraform binary not found at {binary_path}")
        return False

    try:
        from provide.foundation.process import run

        result = run(
            [str(binary_path), "-version"],
            capture_output=True,
            text=True,
            timeout=10,
        )

        if result.returncode == 0:
            # Check if version matches
            version_pattern = rf"Terraform v{re.escape(version)}"
            if re.search(version_pattern, result.stdout):
                logger.debug(f"IBM Terraform {version} verification successful")
                return True
            else:
                logger.error(f"Version mismatch in IBM Terraform output: {result.stdout}")
        else:
            logger.error(f"IBM Terraform version command failed: {result.stderr}")

        return False

    except Exception as e:
        logger.error(f"Failed to verify IBM Terraform installation: {e}")
        return False

Functions