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§
- ext
- Re-exports some helpers from other libraries
Macros§
- construct_
provider - The
construct_provider!
macro accepts the following parameters:
Structs§
- CliLogger
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.- Provider
State 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.- Resource
Args - A struct that holds the input arguments for resource actions, such as the resource’s URN, the raw configuration, and the raw state.
- Resource
Diff - A struct that holds information about the differences between two resource states, such as the properties that have changed during an update operation.
- Resource
Result 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.- Urn
- 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§
- Resource
Action - An enum that defines the possible actions that can be performed on a resource, such as creating, updating, or deleting
Constants§
Traits§
- Provider
- A trait representing a provider in the Mashin SDK.
- Provider
Builder - A trait representing a builder for a provider, which is responsible for initializing the provider and setting up the initial state.
- Provider
Default - A trait representing default behavior for a provider. This is implemented automatically by the macros.
- Resource
- A trait representing a resource in the Mashin SDK.
- Resource
Default - A trait representing default behavior for a resource.
- Resource
Eq - A trait for resource equality comparisons.
- Resource
Serialize - A trait for serializing a resource to its raw state.
Functions§
- build
- deserialize_
state_ field - 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. - merge_
json - Merges two JSON values, deeply combining them into a single JSON value.
Type Aliases§
- Resource
Id - Unique resource id within a provider
- Result
Result<T, Error>
Attribute Macros§
- provider
- 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. - resource
- This proc macro is used to define a resource.