pub struct OpenTofuClient { /* private fields */ }Expand description
A specialized OpenTofu client for infrastructure management.
This client provides a consistent interface for OpenTofu operations:
- Initialize
OpenTofuconfigurations - Plan infrastructure changes
- Apply infrastructure changes
- Destroy infrastructure
Uses CommandExecutor as a collaborator for actual command execution.
Implementations§
Source§impl OpenTofuClient
impl OpenTofuClient
Sourcepub fn new<P: Into<PathBuf>>(working_dir: P) -> Self
pub fn new<P: Into<PathBuf>>(working_dir: P) -> Self
Creates a new OpenTofuClient
§Arguments
working_dir- Path to the directory containingOpenTofuconfiguration files
Sourcepub fn init(&self) -> Result<String, CommandError>
pub fn init(&self) -> Result<String, CommandError>
Sourcepub fn validate(&self) -> Result<String, CommandError>
pub fn validate(&self) -> Result<String, CommandError>
Validate configuration syntax and consistency
§Returns
Ok(String)- The stdout output if the command succeedsErr(CommandError)- Error describing what went wrong
§Errors
This function will return an error if:
- The
OpenTofuvalidate fails due to syntax or consistency errors - The configuration is not initialized
- The working directory does not exist or is not accessible
Sourcepub fn plan(&self, extra_args: &[&str]) -> Result<String, CommandError>
pub fn plan(&self, extra_args: &[&str]) -> Result<String, CommandError>
Plan infrastructure changes
§Arguments
extra_args- Additional arguments to pass to the tofu plan command (e.g., “-var-file=variables.tfvars”)
§Returns
Ok(String)- The stdout output if the command succeedsErr(CommandError)- Error describing what went wrong
§Errors
This function will return an error if:
- The
OpenTofuplan fails - The configuration is not initialized
Sourcepub fn apply(
&self,
auto_approve: bool,
extra_args: &[&str],
) -> Result<String, CommandError>
pub fn apply( &self, auto_approve: bool, extra_args: &[&str], ) -> Result<String, CommandError>
Apply infrastructure changes
§Arguments
auto_approve- Whether to automatically approve the changes without interactive confirmationextra_args- Additional arguments to pass to the tofu apply command (e.g., “-var-file=variables.tfvars”)
§Returns
Ok(String)- The stdout output if the command succeedsErr(CommandError)- Error describing what went wrong
§Errors
This function will return an error if:
- The
OpenTofuapply fails - The configuration is not initialized
Sourcepub fn destroy(
&self,
auto_approve: bool,
extra_args: &[&str],
) -> Result<String, CommandError>
pub fn destroy( &self, auto_approve: bool, extra_args: &[&str], ) -> Result<String, CommandError>
Destroy infrastructure
§Arguments
auto_approve- Whether to automatically approve the destruction without interactive confirmationextra_args- Additional arguments to pass to the tofu destroy command (e.g., “-var-file=variables.tfvars”)
§Returns
Ok(String)- The stdout output if the command succeedsErr(CommandError)- Error describing what went wrong
§Errors
This function will return an error if:
- The
OpenTofudestroy fails - The configuration is not initialized
Sourcepub fn get_instance_info(&self) -> Result<InstanceInfo, OpenTofuError>
pub fn get_instance_info(&self) -> Result<InstanceInfo, OpenTofuError>
Get OpenTofu outputs and parse container information
§Returns
Ok(ContainerInfo)- Parsed container information fromOpenTofuoutputsErr(OpenTofuError)- Error describing what went wrong
§Errors
This function will return an error if:
- The
OpenTofuoutput command fails - The output cannot be parsed as JSON
- The
instance_infosection is missing or malformed
Sourcepub fn working_dir(&self) -> &Path
pub fn working_dir(&self) -> &Path
Get the working directory path
Auto Trait Implementations§
impl Freeze for OpenTofuClient
impl RefUnwindSafe for OpenTofuClient
impl Send for OpenTofuClient
impl Sync for OpenTofuClient
impl Unpin for OpenTofuClient
impl UnsafeUnpin for OpenTofuClient
impl UnwindSafe for OpenTofuClient
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