From b4402cf03b892f1a2678b653d1131f3f9d229418 Mon Sep 17 00:00:00 2001 From: Pierre Mavro Date: Thu, 23 Dec 2021 12:31:13 +0100 Subject: [PATCH] feat: adding custom routes for AWS --- lib/aws/bootstrap/eks-vpc-with-nat-gateways.j2.tf | 7 +++++++ lib/aws/bootstrap/eks-vpc-without-nat-gateways.j2.tf | 8 ++++++++ src/cloud_provider/aws/kubernetes/mod.rs | 9 +++++++++ test_utilities/src/aws.rs | 1 + 4 files changed, 25 insertions(+) diff --git a/lib/aws/bootstrap/eks-vpc-with-nat-gateways.j2.tf b/lib/aws/bootstrap/eks-vpc-with-nat-gateways.j2.tf index 9b87ffad..979c6760 100644 --- a/lib/aws/bootstrap/eks-vpc-with-nat-gateways.j2.tf +++ b/lib/aws/bootstrap/eks-vpc-with-nat-gateways.j2.tf @@ -87,6 +87,13 @@ resource "aws_route_table" "eks_cluster" { gateway_id = aws_internet_gateway.eks_cluster.id } + {% for route in vpc_custom_routing_table %} + route { + cidr_block = "{{ route.destination }}" + gateway_id = "{{ route.target }}" + } + {% endfor %} + tags = local.tags_eks_vpc_public } diff --git a/lib/aws/bootstrap/eks-vpc-without-nat-gateways.j2.tf b/lib/aws/bootstrap/eks-vpc-without-nat-gateways.j2.tf index e522d191..6a98ccbe 100644 --- a/lib/aws/bootstrap/eks-vpc-without-nat-gateways.j2.tf +++ b/lib/aws/bootstrap/eks-vpc-without-nat-gateways.j2.tf @@ -41,6 +41,14 @@ resource "aws_route_table" "eks_cluster" { gateway_id = aws_internet_gateway.eks_cluster.id } + // todo(pmavro): add tests for it when it will be available in the SDK + {% for route in vpc_custom_routing_table %} + route { + cidr_block = "{{ route.destination }}" + gateway_id = "{{ route.target }}" + } + {% endfor %} + tags = local.tags_eks_vpc } diff --git a/src/cloud_provider/aws/kubernetes/mod.rs b/src/cloud_provider/aws/kubernetes/mod.rs index 63b40953..4525bf09 100644 --- a/src/cloud_provider/aws/kubernetes/mod.rs +++ b/src/cloud_provider/aws/kubernetes/mod.rs @@ -54,6 +54,13 @@ pub enum VpcQoveryNetworkMode { WithoutNatGateways, } +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct VpcCustomRoutingTable { + description: String, + destination: String, + target: String, +} + impl fmt::Display for VpcQoveryNetworkMode { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{:?}", self) @@ -81,6 +88,7 @@ pub struct Options { pub vpc_qovery_network_mode: VpcQoveryNetworkMode, pub vpc_cidr_block: String, pub eks_cidr_subnet: String, + pub vpc_custom_routing_table: Vec, pub eks_access_cidr_blocks: Vec, pub rds_cidr_subnet: String, pub documentdb_cidr_subnet: String, @@ -416,6 +424,7 @@ impl<'a> EKS<'a> { context.insert("aws_terraform_backend_bucket", "qovery-terrafom-tfstates"); context.insert("aws_terraform_backend_dynamodb_table", "qovery-terrafom-tfstates"); context.insert("vpc_cidr_block", &vpc_cidr_block); + context.insert("vpc_custom_routing_table", &self.options.vpc_custom_routing_table); context.insert("s3_kubeconfig_bucket", &self.kubeconfig_bucket_name()); // AWS - EKS diff --git a/test_utilities/src/aws.rs b/test_utilities/src/aws.rs index 05176fbc..e9101645 100644 --- a/test_utilities/src/aws.rs +++ b/test_utilities/src/aws.rs @@ -169,6 +169,7 @@ impl Cluster for AWS { vpc_qovery_network_mode: VpcQoveryNetworkMode::WithoutNatGateways, vpc_cidr_block: "10.0.0.0/16".to_string(), eks_cidr_subnet: "20".to_string(), + vpc_custom_routing_table: vec![], eks_access_cidr_blocks: secrets .EKS_ACCESS_CIDR_BLOCKS .unwrap()