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 default domain for applications in this environment.
42    pub default_domain: String,
43    /// The static IP address of the environment (if applicable).
44    pub static_ip: Option<String>,
45}
46
47#[typetag::serde(name = "azure_container_apps_environment")]
48impl ResourceOutputsDefinition for AzureContainerAppsEnvironmentOutputs {
49    fn resource_type() -> ResourceType {
50        AzureContainerAppsEnvironment::RESOURCE_TYPE.clone()
51    }
52
53    fn as_any(&self) -> &dyn Any {
54        self
55    }
56
57    fn box_clone(&self) -> Box<dyn ResourceOutputsDefinition> {
58        Box::new(self.clone())
59    }
60
61    fn outputs_eq(&self, other: &dyn ResourceOutputsDefinition) -> bool {
62        other
63            .as_any()
64            .downcast_ref::<AzureContainerAppsEnvironmentOutputs>()
65            == Some(self)
66    }
67}
68
69// Implementation of ResourceDefinition trait for AzureContainerAppsEnvironment
70#[typetag::serde(name = "azure_container_apps_environment")]
71impl ResourceDefinition for AzureContainerAppsEnvironment {
72    fn resource_type() -> ResourceType {
73        Self::RESOURCE_TYPE.clone()
74    }
75
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
115#[cfg(test)]
116mod tests {
117    use super::*;
118
119    #[test]
120    fn test_azure_container_apps_environment_creation() {
121        let environment = AzureContainerAppsEnvironment::new("my-environment".to_string()).build();
122        assert_eq!(environment.id, "my-environment");
123    }
124}