Skip to content

Commit 8f631fc

Browse files
committed
Reorganizing code
1 parent f407109 commit 8f631fc

File tree

2 files changed

+72
-73
lines changed

2 files changed

+72
-73
lines changed

load-balancing.tf

Lines changed: 0 additions & 73 deletions
This file was deleted.

main.tf

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,75 @@ resource "aws_appautoscaling_target" "scale_target" {
196196
max_capacity = 5
197197
}
198198

199+
# ---------------------------------------------------------------------------------------------------------------------
200+
# AWS SECURITY GROUP - Control Access to ALB
201+
# ---------------------------------------------------------------------------------------------------------------------
202+
resource "aws_security_group" "lb_sg" {
203+
name = "${var.name_preffix}-lb-sg"
204+
description = "Control access to LB"
205+
vpc_id = var.vpc_id
206+
ingress {
207+
protocol = "tcp"
208+
from_port = 80
209+
to_port = 80
210+
cidr_blocks = ["0.0.0.0/0"]
211+
}
212+
egress {
213+
protocol = "-1"
214+
from_port = 0
215+
to_port = 0
216+
cidr_blocks = ["0.0.0.0/0"]
217+
}
218+
tags = {
219+
Name = "${var.name_preffix}-lb-sg"
220+
}
221+
}
222+
223+
# ---------------------------------------------------------------------------------------------------------------------
224+
# AWS LOAD BALANCER
225+
# ---------------------------------------------------------------------------------------------------------------------
226+
resource "aws_lb" "lb" {
227+
name = "${var.name_preffix}-lb"
228+
internal = false
229+
load_balancer_type = "application"
230+
subnets = var.subnets
231+
security_groups = [aws_security_group.lb_sg.id]
232+
enable_deletion_protection = false
233+
enable_cross_zone_load_balancing = true
234+
tags = {
235+
Name = "${var.name_preffix}-lb"
236+
}
237+
}
238+
239+
# ---------------------------------------------------------------------------------------------------------------------
240+
# AWS LOAD BALANCER - Target Group
241+
# ---------------------------------------------------------------------------------------------------------------------
242+
resource "aws_lb_target_group" "lb_tg" {
243+
depends_on = [aws_lb.lb]
244+
name = "${var.name_preffix}-lb-tg"
245+
target_type = "ip"
246+
protocol = "HTTP"
247+
port = var.container_port
248+
vpc_id = var.vpc_id
249+
health_check {
250+
path = "/"
251+
port = var.container_port
252+
}
253+
tags = {
254+
Name = "${var.name_preffix}-lb-tg"
255+
}
256+
}
257+
258+
# ---------------------------------------------------------------------------------------------------------------------
259+
# AWS LOAD BALANCER - Listener
260+
# ---------------------------------------------------------------------------------------------------------------------
261+
resource "aws_lb_listener" "listener" {
262+
depends_on = [aws_lb_target_group.lb_tg]
263+
load_balancer_arn = aws_lb.lb.arn
264+
port = "80"
265+
protocol = "HTTP"
266+
default_action {
267+
target_group_arn = aws_lb_target_group.lb_tg.arn
268+
type = "forward"
269+
}
270+
}

0 commit comments

Comments
 (0)