Commit e9bcec15 authored by Cyril Plisko's avatar Cyril Plisko

Add VPC resource

parent 670b3592
Pipeline #81828581 failed with stage
in 3 minutes and 16 seconds
......@@ -4,6 +4,7 @@ pub use credit_spec::CreditSpecification;
pub use eip::EIp;
pub use instance::Instance;
pub use instance_type::InstanceType;
pub use vpc::Vpc;
pub(crate) use affinity::Affinity;
......@@ -14,3 +15,4 @@ mod credit_spec;
mod eip;
mod instance;
mod instance_type;
mod vpc;
use serde::Serialize;
use crate::skip_serializing_if::SkipSerializingIf;
#[derive(Debug, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct Vpc {
cidr_block: String,
#[serde(skip_serializing_if = "bool::is_false")]
enable_dns_hostnames: bool,
#[serde(skip_serializing_if = "bool::is_false")]
enable_dns_support: bool,
#[serde(skip_serializing_if = "Tenancy::is_default")]
instance_tenancy: Tenancy,
#[serde(skip_serializing_if = "Vec::is_empty")]
tags: Vec<String>,
}
impl Default for Vpc {
fn default() -> Self {
Self {
cidr_block: String::new(),
enable_dns_hostnames: false,
enable_dns_support: false,
instance_tenancy: Tenancy::Default,
tags: Vec::new(),
}
}
}
impl Vpc {
pub fn vpc(cidr_block: impl Into<String>) -> Self {
let cidr_block = cidr_block.into();
Self {
cidr_block,
..Self::default()
}
}
pub fn dedicated(cidr_block: impl Into<String>) -> Self {
let cidr_block = cidr_block.into();
Self {
cidr_block,
instance_tenancy: Tenancy::Dedicated,
..Self::default()
}
}
pub fn host(cidr_block: impl Into<String>) -> Self {
let cidr_block = cidr_block.into();
Self {
cidr_block,
instance_tenancy: Tenancy::Host,
..Self::default()
}
}
}
#[derive(Debug, PartialEq, Serialize)]
#[serde(rename_all = "lowercase")]
enum Tenancy {
Default,
Dedicated,
Host,
}
impl SkipSerializingIf for Tenancy {
fn is_default(&self) -> bool {
*self == Self::Default
}
}
......@@ -2,6 +2,7 @@ use serde::Serialize;
use super::ec2::EIp;
use super::ec2::Instance;
use super::ec2::Vpc;
#[derive(Debug, Serialize)]
#[serde(tag = "Type", content = "Properties")]
......@@ -10,6 +11,8 @@ pub enum Resource {
Instance(Instance),
#[serde(rename = "AWS::EC2::EIP")]
EIp(EIp),
#[serde(rename = "AWS::EC2::VPC")]
Vpc(Vpc),
}
impl Resource {
......@@ -29,3 +32,9 @@ impl From<EIp> for Resource {
Self::EIp(eip)
}
}
impl From<Vpc> for Resource {
fn from(vpc: Vpc) -> Self {
Self::Vpc(vpc)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment