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    /// Azure Container Apps custom domain verification ID.
48    #[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
77// Implementation of ResourceDefinition trait for AzureContainerAppsEnvironment
78impl 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}