This repository has been archived by the owner on Jul 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathalb_external.tf
73 lines (63 loc) · 2.34 KB
/
alb_external.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
## External ALB for Kubernetes services.
resource "aws_lb" "alb_external" {
name = "alb-ext-${local.cluster_name_hash}"
load_balancer_type = "application"
internal = false
idle_timeout = 180
subnets = ["${data.aws_subnet_ids.kops_subnets.ids}"]
security_groups = ["${aws_security_group.alb_external.id}"]
tags = "${map("kubernetes.io/cluster/${var.kops_cluster_name}", "owned")}"
}
resource "aws_security_group" "alb_external" {
name = "alb.ext.nodes.${var.kops_cluster_name}"
description = "Security group for external ALB"
vpc_id = "${data.aws_vpc.kops_vpc.id}"
tags = "${map("kubernetes.io/cluster/${var.kops_cluster_name}", "owned")}"
ingress {
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = "${var.alb_external_allow_ip}"
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_security_group_rule" "alb_external" {
description = "Allow from external ALB"
type = "ingress"
from_port = 0
to_port = 0
protocol = "-1"
source_security_group_id = "${aws_security_group.alb_external.id}"
security_group_id = "${data.aws_security_group.kops_nodes.id}"
}
resource "aws_lb_listener" "alb_external" {
load_balancer_arn = "${aws_lb.alb_external.arn}"
port = 443
protocol = "HTTPS"
certificate_arn = "${data.aws_acm_certificate.service.arn}"
ssl_policy = "ELBSecurityPolicy-2016-08"
default_action {
target_group_arn = "${aws_lb_target_group.alb_external.arn}"
type = "forward"
}
}
resource "aws_lb_target_group" "alb_external" {
name = "alb-ext-${local.cluster_name_hash}"
port = "${var.kubernetes_ingress_port}"
protocol = "HTTP"
vpc_id = "${data.aws_vpc.kops_vpc.id}"
deregistration_delay = 30
tags = "${map("kubernetes.io/cluster/${var.kops_cluster_name}", "owned")}"
health_check {
path = "/healthz"
}
}
resource "aws_autoscaling_attachment" "alb_external" {
autoscaling_group_name = "${join(",", data.aws_autoscaling_groups.kops_nodes.names)}"
alb_target_group_arn = "${aws_lb_target_group.alb_external.arn}"
}