Skip to main content

alien_core/resources/
azure_container_apps_environment.rs

1use 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/// Represents an Azure Container Apps Environment for hosting container applications.
10#[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    /// Identifier for the Container Apps Environment. Must contain only alphanumeric characters, hyphens, and underscores ([A-Za-z0-9-_]).
16    /// Maximum 64 characters.
17    #[builder(start_fn)]
18    pub id: String,
19}
20
21impl AzureContainerAppsEnvironment {
22    /// The resource type identifier for Azure Container Apps Environments
23    pub const RESOURCE_TYPE: ResourceType =
24        ResourceType::from_static("azure_container_apps_environment");
25
26    /// Returns the environment's unique identifier.
27    pub fn id(&self) -> &str {
28        &self.id
29    }
30}
31
32/// Outputs generated by a successfully provisioned Azure Container Apps Environment.
33#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
34#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
35#[serde(rename_all = "camelCase")]
36pub struct AzureContainerAppsEnvironmentOutputs {
37    /// The name of the Container Apps Environment.
38    pub environment_name: String,
39    /// The resource ID of the Container Apps Environment.
40    pub resource_id: String,
41    /// The resource group containing the environment.
42    pub resource_group_name: String,
43    /// The default domain for applications in this environment.
44    pub default_domain: String,
45    /// The static IP address of the environment (if applicable).
46    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
74// Implementation of ResourceDefinition trait for AzureContainerAppsEnvironment
75impl 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}