alien_core/resources/
azure_storage_account.rs1use crate::error::{ErrorData, Result};
2use crate::resource::{ResourceDefinition, ResourceOutputsDefinition, ResourceRef, ResourceType};
3use alien_error::AlienError;
4use bon::Builder;
5use serde::{Deserialize, Serialize};
6use std::any::Any;
7use std::fmt::Debug;
8
9#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Builder)]
11#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
12#[serde(rename_all = "camelCase", deny_unknown_fields)]
13#[builder(start_fn = new)]
14pub struct AzureStorageAccount {
15 #[builder(start_fn)]
18 pub id: String,
19}
20
21impl AzureStorageAccount {
22 pub const RESOURCE_TYPE: ResourceType = ResourceType::from_static("azure_storage_account");
24
25 pub fn id(&self) -> &str {
27 &self.id
28 }
29}
30
31#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
33#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
34#[serde(rename_all = "camelCase")]
35pub struct AzureStorageAccountOutputs {
36 pub account_name: String,
38 pub resource_id: String,
40 pub primary_blob_endpoint: String,
42 pub primary_file_endpoint: String,
44 pub primary_queue_endpoint: String,
46 pub primary_table_endpoint: String,
48 pub primary_access_key: String,
50 pub connection_string: String,
52}
53
54#[typetag::serde(name = "azure_storage_account")]
55impl ResourceOutputsDefinition for AzureStorageAccountOutputs {
56 fn resource_type() -> ResourceType {
57 AzureStorageAccount::RESOURCE_TYPE.clone()
58 }
59
60 fn as_any(&self) -> &dyn Any {
61 self
62 }
63
64 fn box_clone(&self) -> Box<dyn ResourceOutputsDefinition> {
65 Box::new(self.clone())
66 }
67
68 fn outputs_eq(&self, other: &dyn ResourceOutputsDefinition) -> bool {
69 other.as_any().downcast_ref::<AzureStorageAccountOutputs>() == Some(self)
70 }
71}
72
73#[typetag::serde(name = "azure_storage_account")]
75impl ResourceDefinition for AzureStorageAccount {
76 fn resource_type() -> ResourceType {
77 Self::RESOURCE_TYPE.clone()
78 }
79
80 fn get_resource_type(&self) -> ResourceType {
81 Self::resource_type()
82 }
83
84 fn id(&self) -> &str {
85 &self.id
86 }
87
88 fn get_dependencies(&self) -> Vec<ResourceRef> {
89 Vec::new()
90 }
91
92 fn validate_update(&self, _new_config: &dyn ResourceDefinition) -> Result<()> {
93 Err(AlienError::new(ErrorData::InvalidResourceUpdate {
94 resource_id: self.id.clone(),
95 reason: "Azure storage accounts cannot be updated once created".to_string(),
96 }))
97 }
98
99 fn as_any(&self) -> &dyn Any {
100 self
101 }
102
103 fn as_any_mut(&mut self) -> &mut dyn Any {
104 self
105 }
106
107 fn box_clone(&self) -> Box<dyn ResourceDefinition> {
108 Box::new(self.clone())
109 }
110
111 fn resource_eq(&self, other: &dyn ResourceDefinition) -> bool {
112 other.as_any().downcast_ref::<AzureStorageAccount>() == Some(self)
113 }
114}
115
116#[cfg(test)]
117mod tests {
118 use super::*;
119
120 #[test]
121 fn test_azure_storage_account_creation() {
122 let storage_account = AzureStorageAccount::new("my-storage".to_string()).build();
123 assert_eq!(storage_account.id, "my-storage");
124 }
125}