Skip to main content

rusty_cdk_core/shared/
update_delete_policy.rs

1use serde::{Deserialize, Serialize};
2
3pub enum UpdateReplacePolicy {
4    /// `Delete` is the default, deleting the resource (if possible)
5    Delete,
6    /// `Snapshot` deletes it after creating a snapshot
7    Snapshot,
8    /// `Retain` keeps the resource
9    Retain,
10}
11
12impl From<UpdateReplacePolicy> for String {
13    fn from(value: UpdateReplacePolicy) -> String {
14        match value {
15            UpdateReplacePolicy::Delete => "Delete".to_string(),
16            UpdateReplacePolicy::Snapshot => "Snapshot".to_string(),
17            UpdateReplacePolicy::Retain => "Retain".to_string(),
18        }
19    }
20}
21
22/// Determines what happens with an existing resource when it is deleted
23pub enum DeletionPolicy {
24    /// `Delete` deletes the resource (default)
25    Delete,
26    /// `Snapshot` deletes it after creating a snapshot (*if snapshots are possible*)
27    Snapshot,
28    /// `Retain` keeps the resource
29    Retain,
30    /// `RetainExceptOnCreate` keeps the resource, except when it was just created during this stack operation
31    RetainExceptOnCreate,
32}
33
34impl From<DeletionPolicy> for String {
35    fn from(value: DeletionPolicy) -> String {
36        match value {
37            DeletionPolicy::Delete => "Delete".to_string(),
38            DeletionPolicy::Snapshot => "Snapshot".to_string(),
39            DeletionPolicy::Retain => "Retain".to_string(),
40            DeletionPolicy::RetainExceptOnCreate => "RetainExceptOnCreate".to_string(),
41        }
42    }
43}
44
45impl From<&String> for DeletionPolicy {
46    fn from(value: &String) -> DeletionPolicy {
47        match value.as_str() {
48            "Delete" => DeletionPolicy::Delete,
49            "Snapshot" => DeletionPolicy::Snapshot,
50            "Retain" => DeletionPolicy::Retain,
51            "RetainExceptOnCreate" => DeletionPolicy::RetainExceptOnCreate,
52            _ => unreachable!("all deletion policy options to be covered")
53        }
54    }
55}
56
57#[derive(Debug, Serialize, Deserialize)]
58pub struct UpdateDeletePolicyDTO {
59    #[serde(rename = "DeletionPolicy", skip_serializing_if = "Option::is_none")]
60    pub(crate) deletion_policy: Option<String>,
61    #[serde(rename = "UpdateReplacePolicy", skip_serializing_if = "Option::is_none")]
62    pub(crate) update_replace_policy: Option<String>,
63}