-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmod.rs
More file actions
55 lines (52 loc) · 2.24 KB
/
Copy pathmod.rs
File metadata and controls
55 lines (52 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//! 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 `Clock` trait
//! - **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:
//!
//! 1. **Render `OpenTofu` templates** - Generate infrastructure configuration
//! 2. **Initialize `OpenTofu`** - Set up Terraform/`OpenTofu` backend
//! 3. **Validate configuration** - Check syntax and consistency
//! 4. **Plan infrastructure** - Preview changes
//! 5. **Apply infrastructure** - Provision virtual machines
//! 6. **Get instance information** - Retrieve IP address and metadata
//! 7. **Render `Ansible` templates** - Generate configuration with runtime IP
//! 8. **Wait for SSH connectivity** - Ensure VM is reachable
//! 9. **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.
pub mod errors;
pub mod handler;
#[cfg(test)]
mod tests;
// Re-export main types for convenience
pub use errors::ProvisionCommandHandlerError;
pub use handler::ProvisionCommandHandler;