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 default_domain: String,
43 pub static_ip: Option<String>,
45}
46
47impl ResourceOutputsDefinition for AzureContainerAppsEnvironmentOutputs {
48 fn get_resource_type(&self) -> ResourceType {
49 AzureContainerAppsEnvironment::RESOURCE_TYPE.clone()
50 }
51
52 fn as_any(&self) -> &dyn Any {
53 self
54 }
55
56 fn box_clone(&self) -> Box<dyn ResourceOutputsDefinition> {
57 Box::new(self.clone())
58 }
59
60 fn outputs_eq(&self, other: &dyn ResourceOutputsDefinition) -> bool {
61 other
62 .as_any()
63 .downcast_ref::<AzureContainerAppsEnvironmentOutputs>()
64 == Some(self)
65 }
66
67 fn to_json_value(&self) -> serde_json::Result<serde_json::Value> {
68 serde_json::to_value(self)
69 }
70}
71
72impl ResourceDefinition for AzureContainerAppsEnvironment {
74 fn get_resource_type(&self) -> ResourceType {
75 Self::RESOURCE_TYPE
76 }
77
78 fn id(&self) -> &str {
79 &self.id
80 }
81
82 fn get_dependencies(&self) -> Vec<ResourceRef> {
83 Vec::new()
84 }
85
86 fn validate_update(&self, _new_config: &dyn ResourceDefinition) -> Result<()> {
87 Err(AlienError::new(ErrorData::InvalidResourceUpdate {
88 resource_id: self.id.clone(),
89 reason: "Azure container app environments cannot be updated once created".to_string(),
90 }))
91 }
92
93 fn as_any(&self) -> &dyn Any {
94 self
95 }
96
97 fn as_any_mut(&mut self) -> &mut dyn Any {
98 self
99 }
100
101 fn box_clone(&self) -> Box<dyn ResourceDefinition> {
102 Box::new(self.clone())
103 }
104
105 fn resource_eq(&self, other: &dyn ResourceDefinition) -> bool {
106 other
107 .as_any()
108 .downcast_ref::<AzureContainerAppsEnvironment>()
109 == Some(self)
110 }
111
112 fn to_json_value(&self) -> serde_json::Result<serde_json::Value> {
113 serde_json::to_value(self)
114 }
115}
116
117#[cfg(test)]
118mod tests {
119 use super::*;
120
121 #[test]
122 fn test_azure_container_apps_environment_creation() {
123 let environment = AzureContainerAppsEnvironment::new("my-environment".to_string()).build();
124 assert_eq!(environment.id, "my-environment");
125 }
126}