mirror of
https://github.com/mr-vercetti/tf-aws-demo.git
synced 2025-07-01 12:35:33 +02:00
Add ALB
This commit is contained in:
61
modules/alb/main.tf
Executable file
61
modules/alb/main.tf
Executable file
@ -0,0 +1,61 @@
|
||||
resource "aws_security_group" "this" {
|
||||
name = "demo-app-alb-sg"
|
||||
|
||||
vpc_id = var.VPC_ID
|
||||
|
||||
ingress {
|
||||
description = "HTTP"
|
||||
from_port = 80
|
||||
to_port = 80
|
||||
protocol = "tcp"
|
||||
cidr_blocks = ["0.0.0.0/0"]
|
||||
}
|
||||
|
||||
egress {
|
||||
from_port = 0
|
||||
to_port = 0
|
||||
protocol = "-1"
|
||||
cidr_blocks = ["0.0.0.0/0"]
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_lb" "this" {
|
||||
name = "demo-app-alb"
|
||||
|
||||
internal = false
|
||||
load_balancer_type = "application"
|
||||
security_groups = [aws_security_group.this.id]
|
||||
subnets = var.ALB_SUBNETS_IDS
|
||||
|
||||
tags = {
|
||||
Project = var.PROJECT_TAG
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_lb_target_group" "this" {
|
||||
name = "demo-app-alb-tg"
|
||||
port = 80
|
||||
protocol = "HTTP"
|
||||
vpc_id = var.VPC_ID
|
||||
|
||||
health_check {
|
||||
protocol = "HTTP"
|
||||
port = 80
|
||||
path = "/healthcheck.html"
|
||||
healthy_threshold = 2
|
||||
unhealthy_threshold = 2
|
||||
interval = 90
|
||||
timeout = 20
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_lb_listener" "this" {
|
||||
load_balancer_arn = aws_lb.this.arn
|
||||
port = 80
|
||||
protocol = "HTTP"
|
||||
|
||||
default_action {
|
||||
target_group_arn = aws_lb_target_group.this.arn
|
||||
type = "forward"
|
||||
}
|
||||
}
|
3
modules/alb/outputs.tf
Executable file
3
modules/alb/outputs.tf
Executable file
@ -0,0 +1,3 @@
|
||||
output "alb_tg" {
|
||||
value = aws_lb_target_group.this
|
||||
}
|
11
modules/alb/variables.tf
Executable file
11
modules/alb/variables.tf
Executable file
@ -0,0 +1,11 @@
|
||||
variable "VPC_ID" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "PROJECT_TAG" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "ALB_SUBNETS_IDS" {
|
||||
type = list(string)
|
||||
}
|
@ -27,14 +27,6 @@ resource "aws_security_group" "this" {
|
||||
cidr_blocks = ["0.0.0.0/0"]
|
||||
}
|
||||
|
||||
ingress {
|
||||
description = "HTTPS"
|
||||
from_port = 443
|
||||
to_port = 443
|
||||
protocol = "tcp"
|
||||
cidr_blocks = ["0.0.0.0/0"]
|
||||
}
|
||||
|
||||
egress {
|
||||
from_port = 0
|
||||
to_port = 0
|
||||
@ -72,6 +64,7 @@ resource "aws_autoscaling_group" "this" {
|
||||
vpc_zone_identifier = var.VPC_SUBNETS_IDS
|
||||
health_check_type = "ELB"
|
||||
health_check_grace_period = "90"
|
||||
target_group_arns = var.ALB_TARGET_GROUP_ARNS
|
||||
|
||||
tag {
|
||||
key = "Name"
|
||||
|
@ -27,4 +27,9 @@ variable "ASG_MIN_SIZE" {
|
||||
|
||||
variable "ASG_MAX_SIZE" {
|
||||
type = number
|
||||
}
|
||||
|
||||
# ALB
|
||||
variable "ALB_TARGET_GROUP_ARNS" {
|
||||
type = list(string)
|
||||
}
|
Reference in New Issue
Block a user