-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Feat: Private-link * tfdocs update --------- Co-authored-by: Justin Brooks <[email protected]>
- Loading branch information
1 parent
3a7767f
commit 10cc72f
Showing
5 changed files
with
125 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
locals { | ||
max_lb_name_length = 32 - length("-nlb") | ||
lb_name_truncated = "${substr(var.namespace, 0, local.max_lb_name_length)}-nlb" | ||
} | ||
|
||
resource "aws_lb" "nlb" { | ||
name = local.lb_name_truncated | ||
internal = true | ||
load_balancer_type = "network" | ||
subnets = var.network_private_subnets | ||
enable_deletion_protection = var.deletion_protection | ||
} | ||
|
||
resource "aws_lb_target_group" "nlb" { | ||
name = "${var.namespace}-nlb-tg" | ||
protocol = "TCP" | ||
target_type = "alb" | ||
port = 443 | ||
vpc_id = var.vpc_id | ||
|
||
health_check { | ||
protocol = "HTTPS" | ||
path = "/healthz" | ||
matcher = "200-399" | ||
healthy_threshold = 3 | ||
unhealthy_threshold = 3 | ||
interval = 30 | ||
timeout = 10 | ||
port = "traffic-port" | ||
} | ||
} | ||
|
||
data "aws_lb" "alb" { | ||
name = var.alb_name | ||
} | ||
|
||
resource "aws_lb_target_group_attachment" "nlb_to_alb" { | ||
target_group_arn = aws_lb_target_group.nlb.arn | ||
target_id = data.aws_lb.alb.arn | ||
} | ||
|
||
resource "aws_vpc_endpoint_service" "private_link" { | ||
acceptance_required = false | ||
network_load_balancer_arns = [aws_lb.nlb.arn] | ||
allowed_principals = [for id in var.allowed_account_ids : "arn:aws:iam::${id}:root"] | ||
} | ||
|
||
resource "aws_lb_listener" "nlb" { | ||
load_balancer_arn = aws_lb.nlb.arn | ||
protocol = "TCP" | ||
port = 443 | ||
|
||
default_action { | ||
type = "forward" | ||
target_group_arn = aws_lb_target_group.nlb.arn | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
variable "namespace" { | ||
description = "Namespace for naming resources" | ||
type = string | ||
} | ||
|
||
variable "allowed_account_ids" { | ||
description = "List of AWS account IDs allowed to access the VPC Endpoint Service" | ||
type = list(string) | ||
} | ||
|
||
variable "network_private_subnets" { | ||
description = "List of private subnets for the VPC" | ||
type = list(string) | ||
} | ||
|
||
variable "deletion_protection" { | ||
description = "If the instance should have deletion protection enabled. The database / S3 can't be deleted when this value is set to `true`." | ||
type = bool | ||
} | ||
|
||
variable "alb_name" { | ||
description = "Name of the ALB to forward NLB traffic to" | ||
type = string | ||
} | ||
|
||
variable "vpc_id" { | ||
description = "ID of the VPC to create the VPC Endpoint Service in" | ||
type = string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters