Skip to main content

Module state

Expand description

Environment State Marker Types

This module defines the state marker types used in the type-state pattern for the Environment entity. Each state represents a distinct phase in the deployment lifecycle and is enforced at compile-time.

§Type-State Pattern

The type-state pattern uses Rust’s type system to enforce state machine transitions at compile-time. Each state is a distinct type, and the Environment<S> struct is generic over the state type. This ensures that invalid state transitions are caught during compilation rather than at runtime.

§State Lifecycle

§Happy Path

Created → Provisioning → Provisioned → Configuring → Configured
  → Releasing → Released → Running → Destroyed

§Error States

At each operational phase, the system can transition to a corresponding failed state if an error occurs:

  • Provisioning → ProvisionFailed
  • Configuring → ConfigureFailed
  • Releasing → ReleaseFailed
  • Running → RunFailed

§Usage Example

use torrust_tracker_deployer_lib::domain::environment::state::{Created, Provisioning};

// State types are used as type parameters for Environment<S>
// let env: Environment<Created> = Environment::new(name, credentials);
// let env: Environment<Provisioning> = env.start_provisioning();

Structs§

BaseFailureContext
Base failure context shared across all command failures
ConfigureFailed
Error state - Application configuration failed
ConfigureFailureContext
Error context for configure command failures
Configured
Final state - Application configuration completed successfully
Configuring
Intermediate state - Application configuration in progress
Created
Initial state - Environment has been created but no operations performed
DestroyFailed
Error state - Infrastructure destruction failed
DestroyFailureContext
Error context for destroy command failures
Destroyed
Terminal state - Environment has been destroyed
Destroying
Intermediate state - Infrastructure destruction in progress
ProvisionFailed
Error state - Infrastructure provisioning failed
ProvisionFailureContext
Error context for provision command failures
Provisioned
Final state - Infrastructure provisioning completed successfully
Provisioning
Intermediate state - Infrastructure provisioning in progress
ReleaseFailed
Error state - Release preparation failed
ReleaseFailureContext
Structured failure context for release command errors
Released
Final state - Release preparation completed successfully
Releasing
Intermediate state - Release preparation in progress
RunFailed
Error state - Application runtime failed
RunFailureContext
Structured failure context for run command errors
Running
Final state - Application is running

Enums§

AnyEnvironmentState
Type-erased environment that can hold any typed Environment<S> at runtime
ConfigureStep
Steps in the configure workflow
DestroyStep
Steps in the destroy workflow
ProvisionStep
Steps in the provision workflow
ReleaseStep
Steps in the release workflow
RunStep
Steps in the run workflow
StateTypeError
Error type for invalid type conversions when working with type-erased environments