waft.test_resource_manager.vm.terraform_operator module¶
Terraform operations handler for VM management.
- class waft.test_resource_manager.vm.terraform_operator.TerraformOperator(templates_path: Path | None = None)¶
Bases:
objectHandles all Terraform-specific operations.
- apply(variables: Dict[str, Any]) None¶
Apply Terraform configuration.
- Parameters:
variables – Terraform variables
- Raises:
RuntimeError – If terraform apply fails
- apply_output(system: UserConfiguredSystem) dict[str, Any]¶
Extract and apply Terraform deployment details to the system object.
- Parameters:
system – System to update
- Returns:
Terraform outputs dictionary
- Return type:
dict[str, Any]
- delete_workspace(workspace_name: str, force: bool = False) None¶
Ensure Terraform workspace is deleted and default is selected.
- Parameters:
workspace_name – Name of the workspace
force – True to force deletion. Default is False.
- Raises:
RuntimeError – If workspace operations fail
- destroy(variables: Dict[str, Any]) None¶
Destroy Terraform resources.
- Parameters:
variables – Terraform variables
- Raises:
RuntimeError – If terraform destroy fails
- export_workspace(workspace_name: str, locked: bool) str¶
Export a Terraform workspace.
- Parameters:
workspace_name (str) – Name of the workspace
locked (bool) – True to export a locked state, False to export state unlocked
- Raises:
FileNotFoundError – If the workspace does not exist
- Returns:
Exported workspace file path
- Return type:
str
- get_outputs() Dict[str, Any]¶
Get Terraform outputs.
- Returns:
Dictionary of Terraform outputs
- Raises:
RuntimeError – If getting outputs fails
- import_workspace(workspace_name: str, import_zip: Path) None¶
Import a Terraform workspace.
- Parameters:
workspace_name (str) – Name of the workspace
import_zip (Path) – Workspace ZIP file to import
- init() None¶
Initialize Terraform.
- Raises:
RuntimeError – If terraform init fails
- run_command(args: List[str], cwd: Path | None = None, timeout: int | None = None) CompletedProcess¶
Run a Terraform command.
- Parameters:
args – List of Terraform command arguments
cwd – Working directory for the command (defaults to templates_path)
timeout – Command timeout in seconds
- Returns:
subprocess.CompletedProcess with command execution details
- Raises:
RuntimeError – If the command times out or has other execution errors
- select_or_create_workspace(workspace_name: str) None¶
Ensure Terraform workspace exists and is selected.
- Parameters:
workspace_name – Name of the workspace
- Raises:
RuntimeError – If workspace operations fail