This repository was archived by the owner on Jul 11, 2023. It is now read-only.
File tree 11 files changed +169
-0
lines changed
11 files changed +169
-0
lines changed Original file line number Diff line number Diff line change
1
+ # ALB default forward
2
+
3
+ With ` alb ` module setup basic ALB, this module (can be used multiple times) is to setup the detail listener and target group with default action forward.
4
+
5
+ To have more control on the action, attach ` aws_lb_listener_rule ` resource to this listener.
6
+
7
+ Checkout example/alb-test for usage.
Original file line number Diff line number Diff line change
1
+ resource "aws_lb_listener" "lb-listener" {
2
+ load_balancer_arn = var. lb_arn
3
+ port = var. lb_port
4
+ protocol = var. protocol
5
+ ssl_policy = var. protocol == " HTTP" ? " " : var. ssl_policy
6
+ certificate_arn = var. https_cert_arn
7
+ default_action {
8
+ type = " forward"
9
+ target_group_arn = aws_lb_target_group. lb-tg . arn
10
+ }
11
+ }
12
+
13
+ resource "aws_lb_target_group" "lb-tg" {
14
+ name = " ${ var . name_prefix } -tg"
15
+ port = var. service_port
16
+ protocol = " HTTP"
17
+ vpc_id = var. vpc_id
18
+ tags = var. tags
19
+ }
Original file line number Diff line number Diff line change
1
+ output "target_group_arn" {
2
+ value = aws_lb_target_group. lb-tg . arn
3
+ }
4
+
5
+ output "listener_arn" {
6
+ value = aws_lb_listener. lb-listener . arn
7
+ }
Original file line number Diff line number Diff line change
1
+ variable "lb_arn" {
2
+ type = string
3
+ description = " The ARN of the ALB to listen."
4
+ }
5
+
6
+ variable "lb_port" {
7
+ type = number
8
+ description = " The port listened on ALB."
9
+ }
10
+
11
+ variable "protocol" {
12
+ type = string
13
+ description = " Either HTTP or HTTPS."
14
+ }
15
+
16
+ variable "https_cert_arn" {
17
+ type = string
18
+ default = " "
19
+ description = " The ARN of the cert for HTTPS. Required if protocol is HTTPS."
20
+ }
21
+
22
+ variable "ssl_policy" {
23
+ type = string
24
+ default = " ELBSecurityPolicy-2016-08"
25
+ description = " The name of the SSL Policy for the listener. Required if protocol is HTTPS."
26
+ }
27
+
28
+ variable "service_port" {
29
+ type = number
30
+ description = " The port listened on service."
31
+ }
32
+
33
+ variable "vpc_id" {
34
+ type = string
35
+ description = " The identifier of the VPC in which to create the target groups."
36
+ }
37
+
38
+ variable "tags" {
39
+ type = map (string )
40
+ default = {}
41
+ description = " Tags for aws_lb resource."
42
+ }
43
+
44
+ variable "name_prefix" {
45
+ type = string
46
+ }
Original file line number Diff line number Diff line change
1
+ # ALB redirect
2
+
3
+ With ` alb ` module setup basic ALB, this module (can be used multiple times) is to setup a redirect listener. Normally is used for redirecting HTTP request on port 80 to HTTPS on port 443.
4
+
5
+ Checkout example/alb-test for usage.
Original file line number Diff line number Diff line change
1
+ resource "aws_lb_listener" "lb-listener" {
2
+ load_balancer_arn = var. lb_arn
3
+ port = var. http_port
4
+ protocol = " HTTP"
5
+ default_action {
6
+ type = " redirect"
7
+ redirect {
8
+ port = var. https_port
9
+ protocol = " HTTPS"
10
+ status_code = " HTTP_301"
11
+ }
12
+ }
13
+ }
Original file line number Diff line number Diff line change
1
+ variable "lb_arn" {
2
+ type = string
3
+ description = " The ARN of the ALB to listen."
4
+ }
5
+
6
+ variable "http_port" {
7
+ type = number
8
+ description = " The uncrypted web service port listened on ALB. No service should actually servicing on this port."
9
+ }
10
+
11
+ variable "https_port" {
12
+ type = number
13
+ description = " The crypted web service port listened on ALB."
14
+ }
Original file line number Diff line number Diff line change
1
+ # ALB
2
+
3
+ Setup basic aws_lb/aws_lb_listener/aws_lb_target_group resources for HTTP and HTTPS forward/redirect function.
4
+
5
+ Checkout example/alb-test for usage.
Original file line number Diff line number Diff line change
1
+ resource "aws_lb" "alb" {
2
+ name = " ${ var . name_prefix } -alb"
3
+ internal = var. internal
4
+ load_balancer_type = " application"
5
+ security_groups = [aws_security_group . alb_sg . id ]
6
+ subnets = var. subnet_ids
7
+ tags = var. tags
8
+ }
9
+
10
+ resource "aws_security_group" "alb_sg" {
11
+ name_prefix = " ${ var . name_prefix } -alb_sb"
12
+ vpc_id = var. vpc_id
13
+ }
Original file line number Diff line number Diff line change
1
+ output "lb_dns_name" {
2
+ value = aws_lb. alb . dns_name
3
+ }
4
+
5
+ output "lb_zone_id" {
6
+ value = aws_lb. alb . zone_id
7
+ }
8
+
9
+ output "security_group_id" {
10
+ value = aws_security_group. alb_sg . id
11
+ }
12
+
13
+ output "lb_arn" {
14
+ value = aws_lb. alb . arn
15
+ }
Original file line number Diff line number Diff line change
1
+ variable "internal" {
2
+ default = true
3
+ type = bool
4
+ description = " Whether the LB should face Internet."
5
+ }
6
+
7
+ variable "subnet_ids" {
8
+ type = list (string )
9
+ description = " The subnets for LBs to live in."
10
+ }
11
+
12
+ variable "vpc_id" {
13
+ type = string
14
+ description = " The identifier of the VPC in which to create the target groups."
15
+ }
16
+
17
+ variable "tags" {
18
+ type = map (string )
19
+ default = {}
20
+ description = " Tags for aws_lb resource."
21
+ }
22
+
23
+ variable "name_prefix" {
24
+ type = string
25
+ }
You can’t perform that action at this time.
0 commit comments