Skip to main content

fakecloud_cloudformation/
state.rs

1use chrono::{DateTime, Utc};
2use parking_lot::RwLock;
3use std::collections::HashMap;
4use std::sync::Arc;
5
6#[derive(Debug, Clone)]
7pub struct StackResource {
8    pub logical_id: String,
9    pub physical_id: String,
10    pub resource_type: String,
11    pub status: String,
12    /// For custom resources, the Lambda ARN (ServiceToken) used for invocation.
13    pub service_token: Option<String>,
14}
15
16#[derive(Debug, Clone)]
17pub struct Stack {
18    pub name: String,
19    pub stack_id: String,
20    pub template: String,
21    pub status: String,
22    pub resources: Vec<StackResource>,
23    pub parameters: HashMap<String, String>,
24    pub tags: HashMap<String, String>,
25    pub created_at: DateTime<Utc>,
26    pub updated_at: Option<DateTime<Utc>>,
27    pub description: Option<String>,
28    pub notification_arns: Vec<String>,
29}
30
31pub struct CloudFormationState {
32    pub account_id: String,
33    pub region: String,
34    pub stacks: HashMap<String, Stack>,
35}
36
37impl CloudFormationState {
38    pub fn new(account_id: &str, region: &str) -> Self {
39        Self {
40            account_id: account_id.to_string(),
41            region: region.to_string(),
42            stacks: HashMap::new(),
43        }
44    }
45
46    pub fn reset(&mut self) {
47        self.stacks.clear();
48    }
49}
50
51pub type SharedCloudFormationState = Arc<RwLock<CloudFormationState>>;