Resource

Trait Resource 

Source
pub trait Resource: Send + Sync {
    type State<'a>: Serialize + Deserialize<'a> + Send;
    type PrivateState<'a>: Serialize + Deserialize<'a> + Send;
    type ProviderMetaState<'a>: Serialize + Deserialize<'a> + Send;

    // Required methods
    fn schema(&self, diags: &mut Diagnostics) -> Option<Schema>;
    fn read<'a, 'life0, 'life1, 'async_trait>(
        &'life0 self,
        diags: &'life1 mut Diagnostics,
        state: Self::State<'a>,
        private_state: Self::PrivateState<'a>,
        provider_meta_state: Self::ProviderMetaState<'a>,
    ) -> Pin<Box<dyn Future<Output = Option<(Self::State<'a>, Self::PrivateState<'a>)>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'a: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn plan_create<'a, 'life0, 'life1, 'async_trait>(
        &'life0 self,
        diags: &'life1 mut Diagnostics,
        proposed_state: Self::State<'a>,
        config_state: Self::State<'a>,
        provider_meta_state: Self::ProviderMetaState<'a>,
    ) -> Pin<Box<dyn Future<Output = Option<(Self::State<'a>, Self::PrivateState<'a>)>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'a: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn plan_update<'a, 'life0, 'life1, 'async_trait>(
        &'life0 self,
        diags: &'life1 mut Diagnostics,
        prior_state: Self::State<'a>,
        proposed_state: Self::State<'a>,
        config_state: Self::State<'a>,
        prior_private_state: Self::PrivateState<'a>,
        provider_meta_state: Self::ProviderMetaState<'a>,
    ) -> Pin<Box<dyn Future<Output = Option<(Self::State<'a>, Self::PrivateState<'a>, Vec<AttributePath>)>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'a: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn plan_destroy<'a, 'life0, 'life1, 'async_trait>(
        &'life0 self,
        diags: &'life1 mut Diagnostics,
        prior_state: Self::State<'a>,
        prior_private_state: Self::PrivateState<'a>,
        provider_meta_state: Self::ProviderMetaState<'a>,
    ) -> Pin<Box<dyn Future<Output = Option<Self::PrivateState<'a>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'a: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn create<'a, 'life0, 'life1, 'async_trait>(
        &'life0 self,
        diags: &'life1 mut Diagnostics,
        planned_state: Self::State<'a>,
        config_state: Self::State<'a>,
        planned_private_state: Self::PrivateState<'a>,
        provider_meta_state: Self::ProviderMetaState<'a>,
    ) -> Pin<Box<dyn Future<Output = Option<(Self::State<'a>, Self::PrivateState<'a>)>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'a: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn update<'a, 'life0, 'life1, 'async_trait>(
        &'life0 self,
        diags: &'life1 mut Diagnostics,
        prior_state: Self::State<'a>,
        planned_state: Self::State<'a>,
        config_state: Self::State<'a>,
        planned_private_state: Self::PrivateState<'a>,
        provider_meta_state: Self::ProviderMetaState<'a>,
    ) -> Pin<Box<dyn Future<Output = Option<(Self::State<'a>, Self::PrivateState<'a>)>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'a: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn destroy<'a, 'life0, 'life1, 'async_trait>(
        &'life0 self,
        diags: &'life1 mut Diagnostics,
        prior_state: Self::State<'a>,
        planned_private_state: Self::PrivateState<'a>,
        provider_meta_state: Self::ProviderMetaState<'a>,
    ) -> Pin<Box<dyn Future<Output = Option<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'a: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided methods
    fn validate<'a, 'life0, 'life1, 'async_trait>(
        &'life0 self,
        diags: &'life1 mut Diagnostics,
        config: Self::State<'a>,
    ) -> Pin<Box<dyn Future<Output = Option<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'a: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn import<'a, 'life0, 'life1, 'async_trait>(
        &'life0 self,
        diags: &'life1 mut Diagnostics,
        id: String,
    ) -> Pin<Box<dyn Future<Output = Option<(Self::State<'a>, Self::PrivateState<'a>)>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'a: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn upgrade<'a, 'life0, 'life1, 'async_trait>(
        &'life0 self,
        diags: &'life1 mut Diagnostics,
        version: i64,
        prior_state: RawValue,
    ) -> Pin<Box<dyn Future<Output = Option<Self::State<'a>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'a: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

Trait for implementing a resource with automatic serialization/deserialization

See also: DynamicResource

Required Associated Types§

Source

type State<'a>: Serialize + Deserialize<'a> + Send

State of the resource

The state will be automatically serialized/deserialized at the border of the request.

Source

type PrivateState<'a>: Serialize + Deserialize<'a> + Send

Private state of the resource

The private state will be automatically serialized/deserialized at the border of the request.

Source

type ProviderMetaState<'a>: Serialize + Deserialize<'a> + Send

State of the provider metadata

The state will be automatically serialized/deserialized at the border of the request.

Required Methods§

Source

fn schema(&self, diags: &mut Diagnostics) -> Option<Schema>

Get the schema of the resource

§Arguments
  • diags - Diagnostics to record warnings and errors that occured when getting back the schema
§Remarks

The return is ignored if there is an error in diagnostics. If the return is None, an ad-hoc error is added to diagnostics.

Source

fn read<'a, 'life0, 'life1, 'async_trait>( &'life0 self, diags: &'life1 mut Diagnostics, state: Self::State<'a>, private_state: Self::PrivateState<'a>, provider_meta_state: Self::ProviderMetaState<'a>, ) -> Pin<Box<dyn Future<Output = Option<(Self::State<'a>, Self::PrivateState<'a>)>> + Send + 'async_trait>>
where Self: 'async_trait, 'a: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Read the new state of the resource

§Arguments
  • diags - Diagnostics to record warnings and errors that occured during the read
  • state - State as stored in the Terraform state
  • private_state - Private state as stored in the Terraform state
  • provider_meta_state - State of the provider metadata as declared in the Terraform file
§Remarks

Return must be None if the resource has been destroyed externally. Return must be Some if the resource is still there, even if there was errors while reading the resource.

Source

fn plan_create<'a, 'life0, 'life1, 'async_trait>( &'life0 self, diags: &'life1 mut Diagnostics, proposed_state: Self::State<'a>, config_state: Self::State<'a>, provider_meta_state: Self::ProviderMetaState<'a>, ) -> Pin<Box<dyn Future<Output = Option<(Self::State<'a>, Self::PrivateState<'a>)>> + Send + 'async_trait>>
where Self: 'async_trait, 'a: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Plan the creation of a new resource

§Arguments
  • diags - Diagnostics to record warnings and errors that occured during the plan
  • proposed_state - State proposed by Terraform
  • config_state - State as declared in the Terraform file
  • provider_meta_state - State of the provider metadata as declared in the Terraform file
§Remarks

The return is ignored if there is an error in diagnostics. If the return is None, an ad-hoc error is added to diagnostics.

Source

fn plan_update<'a, 'life0, 'life1, 'async_trait>( &'life0 self, diags: &'life1 mut Diagnostics, prior_state: Self::State<'a>, proposed_state: Self::State<'a>, config_state: Self::State<'a>, prior_private_state: Self::PrivateState<'a>, provider_meta_state: Self::ProviderMetaState<'a>, ) -> Pin<Box<dyn Future<Output = Option<(Self::State<'a>, Self::PrivateState<'a>, Vec<AttributePath>)>> + Send + 'async_trait>>
where Self: 'async_trait, 'a: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Plan the changes on the resource

§Arguments
  • diags - Diagnostics to record warnings and errors that occured during the plan
  • prior_state - State as stored in the Terraform state
  • proposed_state - State proposed by Terraform
  • config_state - State as declared in the Terraform file
  • private_state - Private state as stored in the Terraform state
  • provider_meta_state - State of the provider metadata as declared in the Terraform file
§Remarks

The return is ignored if there is an error in diagnostics. If the return is None, an ad-hoc error is added to diagnostics.

Source

fn plan_destroy<'a, 'life0, 'life1, 'async_trait>( &'life0 self, diags: &'life1 mut Diagnostics, prior_state: Self::State<'a>, prior_private_state: Self::PrivateState<'a>, provider_meta_state: Self::ProviderMetaState<'a>, ) -> Pin<Box<dyn Future<Output = Option<Self::PrivateState<'a>>> + Send + 'async_trait>>
where Self: 'async_trait, 'a: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Plan the destruction of the resource

§Arguments
  • diags - Diagnostics to record warnings and errors that occured during the plan
  • prior_state - State as stored in the Terraform state
  • prior_private_state - Private state as stored in the Terraform state
  • provider_meta_state - State of the provider metadata as declared in the Terraform file
§Remarks

The return is ignored if there is an error in diagnostics. If the return is None, an ad-hoc error is added to diagnostics.

Source

fn create<'a, 'life0, 'life1, 'async_trait>( &'life0 self, diags: &'life1 mut Diagnostics, planned_state: Self::State<'a>, config_state: Self::State<'a>, planned_private_state: Self::PrivateState<'a>, provider_meta_state: Self::ProviderMetaState<'a>, ) -> Pin<Box<dyn Future<Output = Option<(Self::State<'a>, Self::PrivateState<'a>)>> + Send + 'async_trait>>
where Self: 'async_trait, 'a: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Create a new resource

§Arguments
  • diags - Diagnostics to record warnings and errors that occured during the creation
  • planned_state - State proposed by the provider upon plan
  • config_state - State as declared in the Terraform file
  • planned_private_state - Private state proposed by the provider upon plan
  • provider_meta_state - State of the provider metadata as declared in the Terraform file
§Remarks

If the return is None, an ad-hoc error is added to diagnostics. Return must be Some if the resource was created, even if there was errors while creating the resource.

Source

fn update<'a, 'life0, 'life1, 'async_trait>( &'life0 self, diags: &'life1 mut Diagnostics, prior_state: Self::State<'a>, planned_state: Self::State<'a>, config_state: Self::State<'a>, planned_private_state: Self::PrivateState<'a>, provider_meta_state: Self::ProviderMetaState<'a>, ) -> Pin<Box<dyn Future<Output = Option<(Self::State<'a>, Self::PrivateState<'a>)>> + Send + 'async_trait>>
where Self: 'async_trait, 'a: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Apply the changes on the resource

§Arguments
  • diags - Diagnostics to record warnings and errors that occured during the update
  • prior_state - State as stored in the Terraform state
  • planned_state - State proposed by the provider upon plan
  • config_state - State as declared in the Terraform file
  • planned_private_state - Private state proposed by the provider upon plan
  • provider_meta_state - State of the provider metadata as declared in the Terraform file
§Remarks

If the return is None, an ad-hoc error is added to diagnostics, and the resource state is kept unchanged. Return must be Some if the resource was updated, even if there was errors while updated the resource.

Source

fn destroy<'a, 'life0, 'life1, 'async_trait>( &'life0 self, diags: &'life1 mut Diagnostics, prior_state: Self::State<'a>, planned_private_state: Self::PrivateState<'a>, provider_meta_state: Self::ProviderMetaState<'a>, ) -> Pin<Box<dyn Future<Output = Option<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'a: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Destroy the resource

§Arguments
  • diags - Diagnostics to record warnings and errors that occured during the destruction
  • prior_state - State as stored in the Terraform state
  • planned_private_state - Private state proposed by the provider upon plan
  • provider_meta_state - State of the provider metadata as declared in the Terraform file
§Remarks

The return is ignored if there is an error in diagnostics. If the return is None, an ad-hoc error is added to diagnostics.

Provided Methods§

Source

fn validate<'a, 'life0, 'life1, 'async_trait>( &'life0 self, diags: &'life1 mut Diagnostics, config: Self::State<'a>, ) -> Pin<Box<dyn Future<Output = Option<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'a: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Validate the configuration of the resource

§Arguments
  • diags - Diagnostics to record warnings and errors that occured during validation
  • config - State as declared in the Terraform file
§Remarks

The return is ignored if there is an error in diagnostics. If the return is None, an ad-hoc error is added to diagnostics.

Source

fn import<'a, 'life0, 'life1, 'async_trait>( &'life0 self, diags: &'life1 mut Diagnostics, id: String, ) -> Pin<Box<dyn Future<Output = Option<(Self::State<'a>, Self::PrivateState<'a>)>> + Send + 'async_trait>>
where Self: 'async_trait, 'a: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Import an existing resource

§Arguments
  • diags - Diagnostics to record warnings and errors that occured during the import
  • id - Opaque string that the provider can use to identify the actual resource to import
§Remarks

If the return is None, an ad-hoc error is added to diagnostics. Return must be Some if the resource was imported, even if there was errors while importing the resource.

Source

fn upgrade<'a, 'life0, 'life1, 'async_trait>( &'life0 self, diags: &'life1 mut Diagnostics, version: i64, prior_state: RawValue, ) -> Pin<Box<dyn Future<Output = Option<Self::State<'a>>> + Send + 'async_trait>>
where Self: 'async_trait, 'a: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Upgrade the resource from a prior version of the resource

§Arguments
  • diags - Diagnostics to record warnings and errors that occured during the import
  • version - Prior version of the resource to upgrade as recorded in Terraform state
  • prior_state - Prior state of the resource to upgrade as recorded in Terraform state
§Remarks

If the return is None, an ad-hoc error is added to diagnostics, and the resource state is kept unchanged. Return must be Some if the resource was upgraded, even if there was errors while upgraded the resource.

Because the schema of the resource might have changed, the prior state must be deserialized explicitely.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§