alien_core/resources/
remote_stack_management.rs1use crate::resource::{ResourceDefinition, ResourceOutputsDefinition, ResourceRef, ResourceType};
2use alien_error::AlienError;
3use bon::Builder;
4use serde::{Deserialize, Serialize};
5use std::any::Any;
6use std::fmt::Debug;
7
8#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Builder)]
21#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
22#[serde(rename_all = "camelCase", deny_unknown_fields)]
23#[builder(start_fn = new)]
24pub struct RemoteStackManagement {
25 #[builder(start_fn)]
28 pub id: String,
29}
30
31impl RemoteStackManagement {
32 pub const RESOURCE_TYPE: ResourceType = ResourceType::from_static("remote-stack-management");
34
35 pub fn id(&self) -> &str {
37 &self.id
38 }
39}
40
41#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
44#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
45#[serde(rename_all = "camelCase", deny_unknown_fields)]
46pub struct RemoteStackManagementOutputs {
47 pub management_resource_id: String,
52
53 pub access_configuration: String,
58}
59
60#[typetag::serde(name = "remote-stack-management")]
62impl ResourceDefinition for RemoteStackManagement {
63 fn resource_type() -> ResourceType {
64 Self::RESOURCE_TYPE.clone()
65 }
66
67 fn get_resource_type(&self) -> ResourceType {
68 Self::resource_type()
69 }
70
71 fn id(&self) -> &str {
72 &self.id
73 }
74
75 fn get_dependencies(&self) -> Vec<ResourceRef> {
76 Vec::new()
79 }
80
81 fn validate_update(&self, new_config: &dyn ResourceDefinition) -> crate::error::Result<()> {
82 if let Some(new_remote_mgmt) = new_config.as_any().downcast_ref::<RemoteStackManagement>() {
84 if self.id != new_remote_mgmt.id {
86 return Err(AlienError::new(
87 crate::error::ErrorData::InvalidResourceUpdate {
88 resource_id: self.id.clone(),
89 reason: "the 'id' field is immutable".to_string(),
90 },
91 ));
92 }
93
94 Ok(())
96 } else {
97 Err(AlienError::new(
98 crate::error::ErrorData::UnexpectedResourceType {
99 resource_id: self.id.clone(),
100 expected: Self::RESOURCE_TYPE,
101 actual: new_config.get_resource_type(),
102 },
103 ))
104 }
105 }
106
107 fn as_any(&self) -> &dyn Any {
108 self
109 }
110
111 fn as_any_mut(&mut self) -> &mut dyn Any {
112 self
113 }
114
115 fn box_clone(&self) -> Box<dyn ResourceDefinition> {
116 Box::new(self.clone())
117 }
118
119 fn resource_eq(&self, other: &dyn ResourceDefinition) -> bool {
120 other
121 .as_any()
122 .downcast_ref::<RemoteStackManagement>()
123 .map(|other_remote_mgmt| self == other_remote_mgmt)
124 .unwrap_or(false)
125 }
126}
127
128#[typetag::serde(name = "remote-stack-management")]
129impl ResourceOutputsDefinition for RemoteStackManagementOutputs {
130 fn resource_type() -> ResourceType {
131 RemoteStackManagement::RESOURCE_TYPE.clone()
132 }
133
134 fn as_any(&self) -> &dyn Any {
135 self
136 }
137
138 fn box_clone(&self) -> Box<dyn ResourceOutputsDefinition> {
139 Box::new(self.clone())
140 }
141
142 fn outputs_eq(&self, other: &dyn ResourceOutputsDefinition) -> bool {
143 other
144 .as_any()
145 .downcast_ref::<RemoteStackManagementOutputs>()
146 == Some(self)
147 }
148}