Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[exmaples/privatelink] make sure we preserve client ip in tg and we a… #42

Merged
merged 2 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions examples/from-private-vpc/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -95,26 +95,26 @@ data "aws_eks_addon_version" "core-dns" {
}

resource "aws_eks_addon" "vpc-cni" {
cluster_name = data.aws_eks_cluster.this.id
addon_name = "vpc-cni"
addon_version = data.aws_eks_addon_version.vpc-cni.version
resolve_conflicts = "OVERWRITE"
cluster_name = module.eks.cluster_id
addon_name = "vpc-cni"
addon_version = data.aws_eks_addon_version.vpc-cni.version
resolve_conflicts_on_update = "OVERWRITE"

service_account_role_arn = module.vpc_cni_ipv4_irsa_role.iam_role_arn
}

resource "aws_eks_addon" "core-dns" {
cluster_name = module.eks.cluster_id
addon_name = "coredns"
addon_version = data.aws_eks_addon_version.core-dns.version
resolve_conflicts = "OVERWRITE"
cluster_name = module.eks.cluster_id
addon_name = "coredns"
addon_version = data.aws_eks_addon_version.core-dns.version
resolve_conflicts_on_update = "OVERWRITE"
}

resource "aws_eks_addon" "kube-proxy" {
cluster_name = module.eks.cluster_id
addon_name = "kube-proxy"
addon_version = data.aws_eks_addon_version.kube-proxy.version
resolve_conflicts = "OVERWRITE"
cluster_name = module.eks.cluster_id
addon_name = "kube-proxy"
addon_version = data.aws_eks_addon_version.kube-proxy.version
resolve_conflicts_on_update = "OVERWRITE"
}

################################################################################
Expand Down
2 changes: 1 addition & 1 deletion examples/from-private-vpc/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ terraform {
}
aws = {
source = "hashicorp/aws"
version = "~> 3.75"
version = "~> 5.28"
}
}
}
2 changes: 1 addition & 1 deletion examples/from-private-vpc/vpc/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ locals {

module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 2.70"
version = "~> 5.2.0"

create_vpc = true
name = var.vpc_name
Expand Down
2 changes: 1 addition & 1 deletion examples/from-scratch-eks-blueprint/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ provider "aws" {

module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 2.70"
version = "~> 5.2.0"

create_vpc = true
name = var.vpc_name
Expand Down
50 changes: 32 additions & 18 deletions examples/from-scratch-with-eks-addon/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ locals {

module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 2.70"
version = "~> 5.2.0"

create_vpc = true
name = var.vpc_name
Expand All @@ -30,7 +30,6 @@ module "vpc" {
single_nat_gateway = true
enable_dns_hostnames = true
enable_dns_support = true
enable_s3_endpoint = true

tags = {
"kubernetes.io/cluster/${var.cluster_name}" = "shared",
Expand All @@ -47,6 +46,21 @@ module "vpc" {
}
}

module "vpc_endpoints" {
source = "terraform-aws-modules/vpc/aws//modules/vpc-endpoints"
version = "~> 5.2.0"

vpc_id = module.vpc.vpc_id

endpoints = {
s3 = {
service = "s3"
service_type = "Gateway"
tags = { Name = "s3-vpc-endpoint" }
},
}
}

################################################################################
# Create EKS cluster
################################################################################
Expand Down Expand Up @@ -161,34 +175,34 @@ data "aws_eks_addon_version" "core-dns" {
}

resource "aws_eks_addon" "ebs_csi" {
cluster_name = data.aws_eks_cluster.this.id
addon_name = "aws-ebs-csi-driver"
addon_version = data.aws_eks_addon_version.ebs_csi.version
resolve_conflicts = "OVERWRITE"
cluster_name = module.eks.cluster_id
addon_name = "aws-ebs-csi-driver"
addon_version = data.aws_eks_addon_version.ebs_csi.version
resolve_conflicts_on_update = "OVERWRITE"

service_account_role_arn = module.ebs_csi_irsa_role.iam_role_arn
}
resource "aws_eks_addon" "vpc-cni" {
cluster_name = data.aws_eks_cluster.this.id
addon_name = "vpc-cni"
addon_version = data.aws_eks_addon_version.vpc-cni.version
resolve_conflicts = "OVERWRITE"
cluster_name = module.eks.cluster_id
addon_name = "vpc-cni"
addon_version = data.aws_eks_addon_version.vpc-cni.version
resolve_conflicts_on_update = "OVERWRITE"

service_account_role_arn = module.vpc_cni_ipv4_irsa_role.iam_role_arn
}

resource "aws_eks_addon" "core-dns" {
cluster_name = module.eks.cluster_id
addon_name = "coredns"
addon_version = data.aws_eks_addon_version.core-dns.version
resolve_conflicts = "OVERWRITE"
cluster_name = module.eks.cluster_id
addon_name = "coredns"
addon_version = data.aws_eks_addon_version.core-dns.version
resolve_conflicts_on_update = "OVERWRITE"
}

resource "aws_eks_addon" "kube-proxy" {
cluster_name = module.eks.cluster_id
addon_name = "kube-proxy"
addon_version = data.aws_eks_addon_version.kube-proxy.version
resolve_conflicts = "OVERWRITE"
cluster_name = module.eks.cluster_id
addon_name = "kube-proxy"
addon_version = data.aws_eks_addon_version.kube-proxy.version
resolve_conflicts_on_update = "OVERWRITE"
}

################################################################################
Expand Down
2 changes: 1 addition & 1 deletion examples/from-scratch-with-eks-addon/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ terraform {
}
aws = {
source = "hashicorp/aws"
version = "~> 3.75"
version = "~> 5.28"
}
}
}
82 changes: 54 additions & 28 deletions examples/from-scratch-with-private-link/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ locals {

module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 2.70"
version = "~> 5.2.0"

create_vpc = true
name = var.vpc_name
Expand All @@ -30,7 +30,6 @@ module "vpc" {
single_nat_gateway = true
enable_dns_hostnames = true
enable_dns_support = true
enable_s3_endpoint = true

tags = {
"kubernetes.io/cluster/${var.cluster_name}" = "shared",
Expand All @@ -47,6 +46,21 @@ module "vpc" {
}
}

module "vpc_endpoints" {
source = "terraform-aws-modules/vpc/aws//modules/vpc-endpoints"
version = "~> 5.2.0"

vpc_id = module.vpc.vpc_id

endpoints = {
s3 = {
service = "s3"
service_type = "Gateway"
tags = { Name = "s3-vpc-endpoint" }
},
}
}

################################################################################
# Create the privatelink resources (NLB, TargetGroup)
################################################################################
Expand All @@ -57,6 +71,8 @@ resource "aws_lb" "this" {
load_balancer_type = "network"
subnets = module.vpc.private_subnets

security_groups = [aws_security_group.this.id]

enable_deletion_protection = false
enable_cross_zone_load_balancing = true

Expand All @@ -74,11 +90,12 @@ resource "aws_vpc_endpoint_service_allowed_principal" "service_to_client" {
}

resource "aws_lb_target_group" "this" {
name = "${var.cluster_name}-nlb-tg"
port = var.target_group.Port
target_type = "ip"
protocol = var.target_group.Protocol
vpc_id = module.vpc.vpc_id
name = "${var.cluster_name}-nlb-tg"
port = 443
target_type = "ip"
protocol = "TCP"
vpc_id = module.vpc.vpc_id
preserve_client_ip = "true"

depends_on = [
aws_lb.this
Expand All @@ -88,26 +105,35 @@ resource "aws_lb_target_group" "this" {

resource "aws_lb_listener" "this" {
load_balancer_arn = aws_lb.this.arn
protocol = var.target_group.Protocol
port = var.target_group.Port
protocol = "TCP"
port = 443
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.this.arn
}
}

resource "aws_security_group" "this" {
description = "Allow connection between NLB and target"
description = "Allow inbound/outbound traffic between NLB and OfAS VPC"
vpc_id = module.vpc.vpc_id
}

resource "aws_security_group_rule" "ingress" {
resource "aws_security_group_rule" "egress" {
security_group_id = aws_security_group.this.id
from_port = var.target_group.Port
to_port = var.target_group.Port
protocol = var.target_group.Protocol
from_port = 0
to_port = 65535
protocol = "-1"
type = "egress"
cidr_blocks = [var.vpc_cidr]
}

resource "aws_security_group_rule" "ingress_https" {
security_group_id = aws_security_group.this.id
from_port = 443
to_port = 443
protocol = "TCP"
type = "ingress"
cidr_blocks = ["0.0.0.0/0"]
cidr_blocks = [var.vpc_cidr]
}


Expand Down Expand Up @@ -161,7 +187,7 @@ module "eks" {
}
ingress_node_9443 = {
description = "Cluster API to load balancer webhook"
protocol = "tcp"
protocol = "TCP"
from_port = 9443
to_port = 9443
type = "ingress"
Expand Down Expand Up @@ -220,26 +246,26 @@ data "aws_eks_addon_version" "core-dns" {
}

resource "aws_eks_addon" "vpc-cni" {
cluster_name = data.aws_eks_cluster.this.id
addon_name = "vpc-cni"
addon_version = data.aws_eks_addon_version.vpc-cni.version
resolve_conflicts = "OVERWRITE"
cluster_name = module.eks.cluster_id
addon_name = "vpc-cni"
addon_version = data.aws_eks_addon_version.vpc-cni.version
resolve_conflicts_on_update = "OVERWRITE"

service_account_role_arn = module.vpc_cni_ipv4_irsa_role.iam_role_arn
}

resource "aws_eks_addon" "core-dns" {
cluster_name = module.eks.cluster_id
addon_name = "coredns"
addon_version = data.aws_eks_addon_version.core-dns.version
resolve_conflicts = "OVERWRITE"
cluster_name = module.eks.cluster_id
addon_name = "coredns"
addon_version = data.aws_eks_addon_version.core-dns.version
resolve_conflicts_on_update = "OVERWRITE"
}

resource "aws_eks_addon" "kube-proxy" {
cluster_name = module.eks.cluster_id
addon_name = "kube-proxy"
addon_version = data.aws_eks_addon_version.kube-proxy.version
resolve_conflicts = "OVERWRITE"
cluster_name = module.eks.cluster_id
addon_name = "kube-proxy"
addon_version = data.aws_eks_addon_version.kube-proxy.version
resolve_conflicts_on_update = "OVERWRITE"
}

################################################################################
Expand Down
2 changes: 1 addition & 1 deletion examples/from-scratch-with-private-link/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ terraform {
}
aws = {
source = "hashicorp/aws"
version = "~> 3.75"
version = "~> 5.28"
}
}
}
Loading
Loading