pub enum AnyEnvironmentState {
Show 15 variants
Created(Environment<Created>),
Provisioning(Environment<Provisioning>),
Provisioned(Environment<Provisioned>),
Configuring(Environment<Configuring>),
Configured(Environment<Configured>),
Releasing(Environment<Releasing>),
Released(Environment<Released>),
Running(Environment<Running>),
Destroying(Environment<Destroying>),
ProvisionFailed(Environment<ProvisionFailed>),
ConfigureFailed(Environment<ConfigureFailed>),
ReleaseFailed(Environment<ReleaseFailed>),
RunFailed(Environment<RunFailed>),
DestroyFailed(Environment<DestroyFailed>),
Destroyed(Environment<Destroyed>),
}Expand description
Type-erased environment that can hold any typed Environment<S> at runtime
This enum enables runtime handling of Environment<S> instances without
knowing their specific state type at compile time. This is essential for:
- Serialization: Saving environments to disk (JSON files)
- Deserialization: Loading environments from disk
- Collections: Storing environments with different states together
- Runtime Inspection: Checking state without compile-time type knowledge
- Generic Interfaces: Passing through non-generic function parameters
§Type Erasure Pattern
Each variant wraps a typed Environment<S> where S is one of the state
marker types defined in this module. The enum variant name acts as a
discriminator (similar to a type column in database Single Table Inheritance).
§Usage Example
use torrust_tracker_deployer_lib::domain::environment::state::AnyEnvironmentState;
// Type erasure: typed -> runtime
// let env: Environment<Provisioned> = ...;
// let any_env: AnyEnvironmentState = env.into_any();
// Serialization
// let json = serde_json::to_string(&any_env)?;
// Deserialization
// let any_env: AnyEnvironmentState = serde_json::from_str(&json)?;
// Type restoration: runtime -> typed
// let env: Environment<Provisioned> = any_env.try_into_provisioned()?;§Design Decision
See ADR: Type Erasure for Environment States for detailed rationale behind this design choice.
Variants§
Created(Environment<Created>)
Environment in Created state
Provisioning(Environment<Provisioning>)
Environment in Provisioning state
Provisioned(Environment<Provisioned>)
Environment in Provisioned state
Configuring(Environment<Configuring>)
Environment in Configuring state
Configured(Environment<Configured>)
Environment in Configured state
Releasing(Environment<Releasing>)
Environment in Releasing state
Released(Environment<Released>)
Environment in Released state
Running(Environment<Running>)
Environment in Running state
Destroying(Environment<Destroying>)
Environment in Destroying state
ProvisionFailed(Environment<ProvisionFailed>)
Environment in ProvisionFailed error state
ConfigureFailed(Environment<ConfigureFailed>)
Environment in ConfigureFailed error state
ReleaseFailed(Environment<ReleaseFailed>)
Environment in ReleaseFailed error state
RunFailed(Environment<RunFailed>)
Environment in RunFailed error state
DestroyFailed(Environment<DestroyFailed>)
Environment in DestroyFailed error state
Destroyed(Environment<Destroyed>)
Environment in Destroyed terminal state
Implementations§
Source§impl AnyEnvironmentState
impl AnyEnvironmentState
Sourcepub fn try_into_configure_failed(
self,
) -> Result<Environment<ConfigureFailed>, StateTypeError>
pub fn try_into_configure_failed( self, ) -> Result<Environment<ConfigureFailed>, StateTypeError>
Attempts to convert AnyEnvironmentState to Environment<ConfigureFailed>
§Errors
Returns StateTypeError::UnexpectedState if the environment is not in ConfigureFailed state.
Source§impl AnyEnvironmentState
impl AnyEnvironmentState
Sourcepub fn try_into_configured(
self,
) -> Result<Environment<Configured>, StateTypeError>
pub fn try_into_configured( self, ) -> Result<Environment<Configured>, StateTypeError>
Attempts to convert AnyEnvironmentState to Environment<Configured>
§Errors
Returns StateTypeError::UnexpectedState if the environment is not in Configured state.
Source§impl AnyEnvironmentState
impl AnyEnvironmentState
Sourcepub fn try_into_configuring(
self,
) -> Result<Environment<Configuring>, StateTypeError>
pub fn try_into_configuring( self, ) -> Result<Environment<Configuring>, StateTypeError>
Attempts to convert AnyEnvironmentState to Environment<Configuring>
§Errors
Returns StateTypeError::UnexpectedState if the environment is not in Configuring state.
Source§impl AnyEnvironmentState
impl AnyEnvironmentState
Sourcepub fn try_into_created(self) -> Result<Environment<Created>, StateTypeError>
pub fn try_into_created(self) -> Result<Environment<Created>, StateTypeError>
Attempts to convert AnyEnvironmentState to Environment<Created>
§Errors
Returns StateTypeError::UnexpectedState if the environment is not in Created state.
Source§impl AnyEnvironmentState
impl AnyEnvironmentState
Sourcepub fn try_into_destroy_failed(
self,
) -> Result<Environment<DestroyFailed>, StateTypeError>
pub fn try_into_destroy_failed( self, ) -> Result<Environment<DestroyFailed>, StateTypeError>
Attempts to convert AnyEnvironmentState to Environment<DestroyFailed>
§Errors
Returns StateTypeError::UnexpectedState if the environment is not in DestroyFailed state.
Source§impl AnyEnvironmentState
impl AnyEnvironmentState
Sourcepub fn try_into_destroyed(
self,
) -> Result<Environment<Destroyed>, StateTypeError>
pub fn try_into_destroyed( self, ) -> Result<Environment<Destroyed>, StateTypeError>
Attempts to convert AnyEnvironmentState to Environment<Destroyed>
§Errors
Returns StateTypeError::UnexpectedState if the environment is not in Destroyed state.
Source§impl AnyEnvironmentState
impl AnyEnvironmentState
Sourcepub fn try_into_destroying(
self,
) -> Result<Environment<Destroying>, StateTypeError>
pub fn try_into_destroying( self, ) -> Result<Environment<Destroying>, StateTypeError>
Attempts to convert AnyEnvironmentState to Environment<Destroying>
§Errors
Returns StateTypeError::UnexpectedState if the environment is not in Destroying state.
Source§impl AnyEnvironmentState
impl AnyEnvironmentState
Sourcepub fn try_into_provision_failed(
self,
) -> Result<Environment<ProvisionFailed>, StateTypeError>
pub fn try_into_provision_failed( self, ) -> Result<Environment<ProvisionFailed>, StateTypeError>
Attempts to convert AnyEnvironmentState to Environment<ProvisionFailed>
§Errors
Returns StateTypeError::UnexpectedState if the environment is not in ProvisionFailed state.
Source§impl AnyEnvironmentState
impl AnyEnvironmentState
Sourcepub fn try_into_provisioned(
self,
) -> Result<Environment<Provisioned>, StateTypeError>
pub fn try_into_provisioned( self, ) -> Result<Environment<Provisioned>, StateTypeError>
Attempts to convert AnyEnvironmentState to Environment<Provisioned>
§Errors
Returns StateTypeError::UnexpectedState if the environment is not in Provisioned state.
Source§impl AnyEnvironmentState
impl AnyEnvironmentState
Sourcepub fn try_into_provisioning(
self,
) -> Result<Environment<Provisioning>, StateTypeError>
pub fn try_into_provisioning( self, ) -> Result<Environment<Provisioning>, StateTypeError>
Attempts to convert AnyEnvironmentState to Environment<Provisioning>
§Errors
Returns StateTypeError::UnexpectedState if the environment is not in Provisioning state.
Source§impl AnyEnvironmentState
impl AnyEnvironmentState
Sourcepub fn try_into_release_failed(
self,
) -> Result<Environment<ReleaseFailed>, StateTypeError>
pub fn try_into_release_failed( self, ) -> Result<Environment<ReleaseFailed>, StateTypeError>
Attempts to convert AnyEnvironmentState to Environment<ReleaseFailed>
§Errors
Returns StateTypeError::UnexpectedState if the environment is not in ReleaseFailed state.
Source§impl AnyEnvironmentState
impl AnyEnvironmentState
Sourcepub fn try_into_released(self) -> Result<Environment<Released>, StateTypeError>
pub fn try_into_released(self) -> Result<Environment<Released>, StateTypeError>
Attempts to convert AnyEnvironmentState to Environment<Released>
§Errors
Returns StateTypeError::UnexpectedState if the environment is not in Released state.
Source§impl AnyEnvironmentState
impl AnyEnvironmentState
Sourcepub fn try_into_releasing(
self,
) -> Result<Environment<Releasing>, StateTypeError>
pub fn try_into_releasing( self, ) -> Result<Environment<Releasing>, StateTypeError>
Attempts to convert AnyEnvironmentState to Environment<Releasing>
§Errors
Returns StateTypeError::UnexpectedState if the environment is not in Releasing state.
Source§impl AnyEnvironmentState
impl AnyEnvironmentState
Sourcepub fn try_into_run_failed(
self,
) -> Result<Environment<RunFailed>, StateTypeError>
pub fn try_into_run_failed( self, ) -> Result<Environment<RunFailed>, StateTypeError>
Attempts to convert AnyEnvironmentState to Environment<RunFailed>
§Errors
Returns StateTypeError::UnexpectedState if the environment is not in RunFailed state.
Source§impl AnyEnvironmentState
impl AnyEnvironmentState
Sourcepub fn try_into_running(self) -> Result<Environment<Running>, StateTypeError>
pub fn try_into_running(self) -> Result<Environment<Running>, StateTypeError>
Attempts to convert AnyEnvironmentState to Environment<Running>
§Errors
Returns StateTypeError::UnexpectedState if the environment is not in Running state.
Source§impl AnyEnvironmentState
impl AnyEnvironmentState
Sourcepub fn name(&self) -> &EnvironmentName
pub fn name(&self) -> &EnvironmentName
Get the environment name regardless of current state
This method provides access to the environment name without needing to pattern match on the specific state variant.
§Returns
A reference to the EnvironmentName contained within the environment.
Sourcepub fn state_name(&self) -> &'static str
pub fn state_name(&self) -> &'static str
Get the state name as a string
Returns a static string identifier for the current state. This is useful for logging, error messages, and displaying state information to users.
§Returns
A static string representing the state name (e.g., “created”, “provisioning”).
Sourcepub fn state_display_name(&self) -> &'static str
pub fn state_display_name(&self) -> &'static str
Returns a human-readable display name for the current state.
This provides a user-friendly representation suitable for CLI output, reports, and other user-facing contexts. Failed states include a space for readability (e.g., “Provision Failed”).
§Returns
A static string representing the display name (e.g., “Created”, “Provision Failed”).
Sourcepub fn is_success_state(&self) -> bool
pub fn is_success_state(&self) -> bool
Check if the environment is in a success (non-error) state
Success states are those representing normal operation flow, including
transient states (like Provisioning) and terminal success states
(like Running, Destroyed).
§Returns
true if the environment is in a success state, false for error states.
Sourcepub fn is_error_state(&self) -> bool
pub fn is_error_state(&self) -> bool
Check if the environment is in an error state
Error states indicate that an operation failed during the environment’s lifecycle (provisioning, configuration, release, or runtime).
§Returns
true if the environment is in an error state, false otherwise.
Sourcepub fn is_terminal_state(&self) -> bool
pub fn is_terminal_state(&self) -> bool
Check if the environment is in a terminal state
Terminal states are final states where no more transitions are expected.
This includes both successful terminal states (Running, Destroyed)
and error states (all *Failed variants).
§Returns
true if the environment is in a terminal state, false otherwise.
Sourcepub fn error_details(&self) -> Option<&str>
pub fn error_details(&self) -> Option<&str>
Get error details if the environment is in an error state
For error states (*Failed), this returns the description of the
operation that failed. For non-error states, returns None.
§Returns
Some(&str)containing the failed operation description for error statesNonefor success states
Sourcepub fn instance_name(&self) -> &InstanceName
pub fn instance_name(&self) -> &InstanceName
Get the instance name regardless of current state
This method provides access to the instance name without needing to pattern match on the specific state variant.
§Returns
A reference to the InstanceName contained within the environment.
Sourcepub fn profile_name(&self) -> &ProfileName
pub fn profile_name(&self) -> &ProfileName
Sourcepub fn ssh_credentials(&self) -> &SshCredentials
pub fn ssh_credentials(&self) -> &SshCredentials
Get the SSH credentials regardless of current state
This method provides access to the SSH credentials without needing to pattern match on the specific state variant.
§Returns
A reference to the SshCredentials contained within the environment.
Sourcepub fn ssh_port(&self) -> u16
pub fn ssh_port(&self) -> u16
Get the SSH port regardless of current state
This method provides access to the SSH port without needing to pattern match on the specific state variant.
§Returns
The SSH port number.
Sourcepub fn provider_name(&self) -> &'static str
pub fn provider_name(&self) -> &'static str
Get the provider name regardless of current state
This method provides access to the provider name without needing to pattern match on the specific state variant.
§Returns
A static string representing the provider name (e.g., “lxd”, “hetzner”).
Sourcepub fn provider_display_name(&self) -> &'static str
pub fn provider_display_name(&self) -> &'static str
Get the human-readable provider display name regardless of current state
This method provides access to the provider display name without needing to pattern match on the specific state variant.
§Returns
A static string representing the provider display name (e.g., “LXD”, “Hetzner Cloud”).
Sourcepub fn tracker_config(&self) -> &TrackerConfig
pub fn tracker_config(&self) -> &TrackerConfig
Get the tracker configuration regardless of current state
This method provides access to the tracker configuration without needing to pattern match on the specific state variant.
§Returns
A reference to the TrackerConfig contained within the environment.
Sourcepub fn instance_ip(&self) -> Option<IpAddr>
pub fn instance_ip(&self) -> Option<IpAddr>
Get the instance IP address if available, regardless of current state
This method provides access to the instance IP without needing to pattern match on the specific state variant.
§Returns
Some(IpAddr)if the environment has been provisionedNoneif the environment hasn’t been provisioned yet
Sourcepub fn created_at(&self) -> DateTime<Utc>
pub fn created_at(&self) -> DateTime<Utc>
Get when the environment was created
This method provides access to the creation timestamp without needing to pattern match on the specific state variant.
§Returns
The UTC timestamp when the environment was created.
Sourcepub fn provision_method(&self) -> Option<ProvisionMethod>
pub fn provision_method(&self) -> Option<ProvisionMethod>
Get the provision method if available, regardless of current state
This method provides access to the provision method without needing to pattern match on the specific state variant.
§Returns
Some(ProvisionMethod::Provisioned)if the instance was provisioned viaOpenTofuSome(ProvisionMethod::Registered)if the instance was registered from existing infrastructureNoneif the provision method hasn’t been set yet (legacy or pre-provisioned state)
Sourcepub fn service_endpoints(&self) -> Option<&ServiceEndpoints>
pub fn service_endpoints(&self) -> Option<&ServiceEndpoints>
Get the service endpoints if available, regardless of current state
This method provides access to the service endpoints without needing to pattern match on the specific state variant.
§Returns
Some(&ServiceEndpoints)if services have been started and URLs are availableNoneif services haven’t been started yet or URLs weren’t recorded
Sourcepub fn prometheus_config(&self) -> Option<&PrometheusConfig>
pub fn prometheus_config(&self) -> Option<&PrometheusConfig>
Get the Prometheus configuration if enabled, regardless of current state
This method provides access to the Prometheus configuration without needing to pattern match on the specific state variant.
§Returns
Some(&PrometheusConfig)if Prometheus is configured for this environmentNoneif Prometheus is not enabled
Sourcepub fn grafana_config(&self) -> Option<&GrafanaConfig>
pub fn grafana_config(&self) -> Option<&GrafanaConfig>
Get the Grafana configuration if enabled, regardless of current state
This method provides access to the Grafana configuration without needing to pattern match on the specific state variant.
§Returns
Some(&GrafanaConfig)if Grafana is configured for this environmentNoneif Grafana is not enabled
Sourcepub fn https_config(&self) -> Option<&HttpsConfig>
pub fn https_config(&self) -> Option<&HttpsConfig>
Get the HTTPS configuration if enabled, regardless of current state
This method provides access to the HTTPS configuration without needing to pattern match on the specific state variant.
§Returns
Some(&HttpsConfig)if HTTPS/TLS is configured for this environmentNoneif HTTPS is not enabled
Sourcepub fn is_registered(&self) -> bool
pub fn is_registered(&self) -> bool
Check if this environment was registered from existing infrastructure
Registered environments have infrastructure that was created externally and cannot be destroyed by this tool. The destroy command will only clean up local state for registered environments.
§Returns
true if the environment was registered (not provisioned), false otherwise.
Sourcepub fn collect_tls_domains(&self) -> Vec<DomainName>
pub fn collect_tls_domains(&self) -> Vec<DomainName>
Collect all TLS-enabled domains from the environment configuration
Gathers domains from all services that have TLS enabled: HTTP API, HTTP trackers, health check API, and Grafana.
This method is useful for operations that need to work with all configured domains, such as DNS resolution checks, certificate management, or reporting.
§Returns
A vector of all TLS domains configured in the environment. Returns an empty vector if no TLS domains are configured.
Sourcepub fn destroy(self) -> Result<Environment<Destroyed>, StateTypeError>
pub fn destroy(self) -> Result<Environment<Destroyed>, StateTypeError>
Destroy the environment, transitioning it to the Destroyed state
This method provides a unified interface to destroy an environment regardless of its current state. It encapsulates the repetitive match pattern that would otherwise be needed in calling code.
§Returns
Ok(Environment<Destroyed>)if the environment was successfully destroyedErr(StateTypeError)if the environment is already in theDestroyedstate
§Errors
Returns StateTypeError::UnexpectedState if called on an environment
already in the Destroyed state.
Sourcepub fn tofu_build_dir(&self) -> PathBuf
pub fn tofu_build_dir(&self) -> PathBuf
Get the OpenTofu build directory path regardless of current state
This method provides a unified interface to access the build directory
for OpenTofu operations without needing to pattern match on the
specific state variant.
The path is returned consistently regardless of the environment’s state. The caller is responsible for determining how to use the path based on their specific needs and the environment’s current state.
§Returns
The path to the OpenTofu build directory for the LXD provider.
Trait Implementations§
Source§impl Clone for AnyEnvironmentState
impl Clone for AnyEnvironmentState
Source§impl Debug for AnyEnvironmentState
impl Debug for AnyEnvironmentState
Source§impl<'de> Deserialize<'de> for AnyEnvironmentState
impl<'de> Deserialize<'de> for AnyEnvironmentState
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for AnyEnvironmentState
Display implementation for user-friendly state representation
impl Display for AnyEnvironmentState
Display implementation for user-friendly state representation
Formats the environment state in a human-readable way, including the environment name, current state, and error details if applicable.
§Examples
Environment 'my-env' is in state: provisioning
Environment 'my-env' is in state: provision_failed (failed at: network timeout)Auto Trait Implementations§
impl Freeze for AnyEnvironmentState
impl RefUnwindSafe for AnyEnvironmentState
impl Send for AnyEnvironmentState
impl Sync for AnyEnvironmentState
impl Unpin for AnyEnvironmentState
impl UnsafeUnpin for AnyEnvironmentState
impl UnwindSafe for AnyEnvironmentState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
type Err = !
fn into_result(self) -> Result<T, <T as IntoResult<T>>::Err>
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.