Expand description
Provision Command Module
This module implements the delivery-agnostic ProvisionCommandHandler
for orchestrating infrastructure provisioning business logic.
§Architecture
The ProvisionCommandHandler implements the Command Pattern and uses Dependency Injection
to interact with infrastructure services through interfaces:
- Repository Pattern: Persists environment state via
EnvironmentRepository - Clock Abstraction: Provides deterministic time for testing via
Clocktrait - Domain-Driven Design: Uses domain objects from
domain::environment
§Design Principles
- Delivery-Agnostic: Works with CLI, REST API, or any delivery mechanism
- Asynchronous: Uses async/await for network operations
- Explicit State Transitions: Type-safe state machine for environment lifecycle
- Explicit Errors: All errors implement
.help()with actionable guidance
§Provisioning Workflow
The command handler orchestrates a multi-step workflow:
- Render
OpenTofutemplates - Generate infrastructure configuration - Initialize
OpenTofu- Set up Terraform/OpenTofubackend - Validate configuration - Check syntax and consistency
- Plan infrastructure - Preview changes
- Apply infrastructure - Provision virtual machines
- Get instance information - Retrieve IP address and metadata
- Render
Ansibletemplates - Generate configuration with runtime IP - Wait for SSH connectivity - Ensure VM is reachable
- Wait for cloud-init - Ensure system is ready for configuration
§State Management
The command handler integrates with the type-state pattern for environment lifecycle:
- Accepts
Environment<Created>as input - Transitions to
Environment<Provisioning>at start - Returns
Environment<Provisioned>on success - Transitions to
Environment<ProvisionFailed>on error
State is persisted after each transition using the injected repository.
Re-exports§
pub use errors::ProvisionCommandHandlerError;pub use handler::ProvisionCommandHandler;