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