pub struct DestroyCommandHandler { /* private fields */ }Expand description
DestroyCommandHandler orchestrates the complete infrastructure destruction workflow
The DestroyCommandHandler orchestrates the complete infrastructure teardown workflow.
This command handler handles all steps required to destroy infrastructure:
- Destroy infrastructure via
OpenTofu - Clean up state files
- Transition environment to
Destroyedstate
§State Management
The command handler integrates with the type-state pattern for environment lifecycle:
- Accepts
Environment<S>(any state) as input via environment name lookup - Transitions to
Environment<Destroying>at start - Returns
Environment<Destroyed>on success - Transitions to
Environment<DestroyFailed>on error
State is persisted after each transition using the injected repository.
§Idempotency
The destroy operation is idempotent. Running it multiple times on the same environment will:
- Succeed if the infrastructure is already destroyed
- Report appropriate status to the user
- Not fail due to missing resources
Implementations§
Source§impl DestroyCommandHandler
impl DestroyCommandHandler
Sourcepub fn new(
repository: Arc<dyn EnvironmentRepository>,
clock: Arc<dyn Clock>,
) -> Self
pub fn new( repository: Arc<dyn EnvironmentRepository>, clock: Arc<dyn Clock>, ) -> Self
Create a new DestroyCommandHandler
Sourcepub fn execute(
&self,
env_name: &EnvironmentName,
) -> Result<Environment<Destroyed>, DestroyCommandHandlerError>
pub fn execute( &self, env_name: &EnvironmentName, ) -> Result<Environment<Destroyed>, DestroyCommandHandlerError>
Execute the complete destruction workflow
§Arguments
env_name- The name of the environment to destroy
§Returns
Returns the destroyed environment
§Errors
Returns an error if any step in the destruction workflow fails:
- Environment not found or cannot be loaded
- Environment is in an invalid state for destruction
OpenTofudestroy fails- Unable to persist the destroyed state
On error, the environment transitions to DestroyFailed state and is persisted.
Auto Trait Implementations§
impl !RefUnwindSafe for DestroyCommandHandler
impl !Send for DestroyCommandHandler
impl !Sync for DestroyCommandHandler
impl !UnwindSafe for DestroyCommandHandler
impl Freeze for DestroyCommandHandler
impl Unpin for DestroyCommandHandler
impl UnsafeUnpin for DestroyCommandHandler
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
Mutably borrows from an owned value. Read more
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> ⓘ
Converts
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> ⓘ
Converts
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>
Wrap the input message
T in a tonic::Request