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}
29
30pub struct CloudFormationState {
31    pub account_id: String,
32    pub region: String,
33    pub stacks: HashMap<String, Stack>,
34}
35
36impl CloudFormationState {
37    pub fn new(account_id: &str, region: &str) -> Self {
38        Self {
39            account_id: account_id.to_string(),
40            region: region.to_string(),
41            stacks: HashMap::new(),
42        }
43    }
44
45    pub fn reset(&mut self) {
46        self.stacks.clear();
47    }
48}
49
50pub type SharedCloudFormationState = Arc<RwLock<CloudFormationState>>;