Crate mashin_sdk
source ·Expand description
The Mashin SDK is a library designed to facilitate the management of resources and providers within the Mashin engine for infrastructure-as-code solutions. It provides a powerful and flexible way to define, create, update, and delete resources across various cloud services, streamlining the process of creating and managing infrastructure components.
The construct_provider!
and resource
macros are essential for developers to create custom
providers and resources, which can then be exposed to the Mashin engine, enabling Ops teams to
efficiently manage infrastructure components.
-
construct_provider!
macro: This macro simplifies the process of creating custom providers by generating the necessary boilerplate code for implementing theProvider
trait. Users only need to provide the provider-specific configuration and logic for handling resources. -
resource
macro: This macro generates the required code to implement theResource
trait for custom resources. Users only need to define the resource’s properties and implement the logic for creating, updating, and deleting the resource using the provider.
Key concepts
-
Provider: A struct that represents a cloud service, such as AWS, Azure, or GCP, and implements the logic for creating, updating, and deleting resources on that service.
-
Resource: A struct that represents an individual infrastructure component, such as a virtual machine, a network, or a database.
Re-exports
This module re-exports some helpers from other libraries, such as serde
, async_trait
,
parking_lot
, serde_json
, and tokio
. These re-exports are available under the ext
submodule.
Example
mashin_sdk::construct_provider!(
test_provider,
resources = [my_resource],
);
#[mashin_sdk::resource]
pub mod my_resource {
#[mashin::config]
pub struct Config {}
#[mashin::resource]
pub struct Resource {}
#[mashin::calls]
impl mashin_sdk::Resource for Resource { ... }
}
Modules
- Re-exports some helpers from other libraries
Macros
- The
construct_provider!
macro accepts the following parameters:
Structs
CliLogger
is a wrapper around theenv_logger::Logger
that provides a convenient way to pass a single logger instance to providers, facilitating log output to the console and improving traceability.ProviderState
is a storage container for provider-specific data that can be shared between provider and resource instances. It allows providers to store and access data such as API clients or other shared information.- A struct that holds the input arguments for resource actions, such as the resource’s URN, the raw configuration, and the raw state.
- A struct that holds information about the differences between two resource states, such as the properties that have changed during an update operation.
ResourceResult
represents the serialized state of a resource after it has been processed by a provider. The Mashin engine uses this data to compare the actual state with the desired state, determining whether any changes have occurred.- URNs (Uniform Resource Name) are used in Mashin to uniquely identify providers and resources within the system. They serve as the primary means of routing and referencing between different components in the infrastructure.
Enums
- An enum that defines the possible actions that can be performed on a resource, such as creating, updating, or deleting
Constants
Traits
- A trait representing a provider in the Mashin SDK.
- A trait representing a builder for a provider, which is responsible for initializing the provider and setting up the initial state.
- A trait representing default behavior for a provider. This is implemented automatically by the macros.
- A trait representing a resource in the Mashin SDK.
- A trait representing default behavior for a resource.
- A trait for resource equality comparisons.
- A trait for serializing a resource to its raw state.
Functions
- This function is a custom deserializer for resource state fields. It checks if the field is an object containing a
__value
key. If the__value
key is present, its associated value is used for deserialization, otherwise the entire object is used. - Merges two JSON values, deeply combining them into a single JSON value.
Type Definitions
- Unique resource id within a provider
Result<T, Error>
Attribute Macros
- This proc macro is used internally by the
construct_provider!
macro and should not be used directly by users. This macro generates the necessary code for creating a provider, including the provider struct, configuration, resources link, and state management. It also handles the provider’s lifecycle, such as the initialization and the drop operation. - This proc macro is used to define a resource.