use crate::{ManagementConfig, Platform, ResourceType, StackSettings, StackState};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
pub const MIN_SUPPORTED_SETUP_IMPORT_FORMAT_VERSION: u32 = 1;
pub const CURRENT_SETUP_IMPORT_FORMAT_VERSION: u32 = 1;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[serde(rename_all = "lowercase")]
pub enum ImportSourceKind {
CloudFormation,
Terraform,
Helm,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[serde(rename_all = "camelCase")]
pub struct StackImportRequest {
pub setup_import_format_version: u32,
pub deployment_group_token: String,
pub deployment_name: String,
pub resource_prefix: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub source_kind: Option<ImportSourceKind>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub setup_metadata: Option<serde_json::Value>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub release_id: Option<String>,
pub platform: Platform,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub base_platform: Option<Platform>,
pub region: String,
pub setup_target: String,
pub setup_fingerprint: String,
pub setup_fingerprint_version: u32,
pub stack_settings: StackSettings,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub management_config: Option<ManagementConfig>,
#[serde(default, skip_serializing_if = "HashMap::is_empty")]
pub input_values: HashMap<String, serde_json::Value>,
pub resources: Vec<ImportedResource>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[serde(rename_all = "camelCase")]
pub struct ImportedResource {
pub id: String,
#[serde(rename = "type")]
pub resource_type: ResourceType,
#[cfg_attr(feature = "openapi", schema(value_type = Object))]
pub import_data: serde_json::Value,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[serde(rename_all = "camelCase")]
pub struct StackImportResponse {
pub deployment_id: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub deployment_token: Option<String>,
pub stack_settings: StackSettings,
pub stack_state: StackState,
}
#[cfg(test)]
mod tests {
use super::ImportSourceKind;
#[test]
fn import_source_kind_serializes_cloudformation_without_separator() {
let value = serde_json::to_value(ImportSourceKind::CloudFormation).unwrap();
assert_eq!(value, "cloudformation");
let source: ImportSourceKind = serde_json::from_value(value).unwrap();
assert_eq!(source, ImportSourceKind::CloudFormation);
}
}