alien_core/resources/
azure_container_apps_environment.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 AzureContainerAppsEnvironment {
15 #[builder(start_fn)]
18 pub id: String,
19}
20
21impl AzureContainerAppsEnvironment {
22 pub const RESOURCE_TYPE: ResourceType =
24 ResourceType::from_static("azure_container_apps_environment");
25
26 pub fn id(&self) -> &str {
28 &self.id
29 }
30}
31
32#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
34#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
35#[serde(rename_all = "camelCase")]
36pub struct AzureContainerAppsEnvironmentOutputs {
37 pub environment_name: String,
39 pub resource_id: String,
41 pub resource_group_name: String,
43 pub default_domain: String,
45 pub static_ip: Option<String>,
47}
48
49impl ResourceOutputsDefinition for AzureContainerAppsEnvironmentOutputs {
50 fn get_resource_type(&self) -> ResourceType {
51 AzureContainerAppsEnvironment::RESOURCE_TYPE.clone()
52 }
53
54 fn as_any(&self) -> &dyn Any {
55 self
56 }
57
58 fn box_clone(&self) -> Box<dyn ResourceOutputsDefinition> {
59 Box::new(self.clone())
60 }
61
62 fn outputs_eq(&self, other: &dyn ResourceOutputsDefinition) -> bool {
63 other
64 .as_any()
65 .downcast_ref::<AzureContainerAppsEnvironmentOutputs>()
66 == Some(self)
67 }
68
69 fn to_json_value(&self) -> serde_json::Result<serde_json::Value> {
70 serde_json::to_value(self)
71 }
72}
73
74impl ResourceDefinition for AzureContainerAppsEnvironment {
76 fn get_resource_type(&self) -> ResourceType {
77 Self::RESOURCE_TYPE
78 }
79
80 fn id(&self) -> &str {
81 &self.id
82 }
83
84 fn get_dependencies(&self) -> Vec<ResourceRef> {
85 Vec::new()
86 }
87
88 fn validate_update(&self, _new_config: &dyn ResourceDefinition) -> Result<()> {
89 Err(AlienError::new(ErrorData::InvalidResourceUpdate {
90 resource_id: self.id.clone(),
91 reason: "Azure container app environments cannot be updated once created".to_string(),
92 }))
93 }
94
95 fn as_any(&self) -> &dyn Any {
96 self
97 }
98
99 fn as_any_mut(&mut self) -> &mut dyn Any {
100 self
101 }
102
103 fn box_clone(&self) -> Box<dyn ResourceDefinition> {
104 Box::new(self.clone())
105 }
106
107 fn resource_eq(&self, other: &dyn ResourceDefinition) -> bool {
108 other
109 .as_any()
110 .downcast_ref::<AzureContainerAppsEnvironment>()
111 == Some(self)
112 }
113
114 fn to_json_value(&self) -> serde_json::Result<serde_json::Value> {
115 serde_json::to_value(self)
116 }
117}
118
119#[cfg(test)]
120mod tests {
121 use super::*;
122
123 #[test]
124 fn test_azure_container_apps_environment_creation() {
125 let environment = AzureContainerAppsEnvironment::new("my-environment".to_string()).build();
126 assert_eq!(environment.id, "my-environment");
127 }
128}