Infrastructure up and running
This commit is contained in:
parent
80141ce683
commit
7da6e0a5f7
41
tf/alb.tf
41
tf/alb.tf
|
@ -32,16 +32,45 @@ resource "aws_lb" "server" {
|
|||
subnets = data.aws_subnet_ids.default.ids
|
||||
}
|
||||
|
||||
resource "aws_lb_target_group" "server_http" {
|
||||
resource "aws_lb_target_group" "server" {
|
||||
name = "riju-server-http"
|
||||
port = 80
|
||||
protocol = "HTTP"
|
||||
vpc_id = data.aws_vpc.default.id
|
||||
}
|
||||
|
||||
resource "aws_lb_target_group" "server_https" {
|
||||
name = "riju-server-https"
|
||||
port = 443
|
||||
protocol = "HTTPS"
|
||||
vpc_id = data.aws_vpc.default.id
|
||||
resource "aws_lb_listener" "server_http" {
|
||||
load_balancer_arn = aws_lb.server.arn
|
||||
port = "80"
|
||||
protocol = "HTTP"
|
||||
|
||||
default_action {
|
||||
type = "redirect"
|
||||
|
||||
redirect {
|
||||
port = "443"
|
||||
protocol = "HTTPS"
|
||||
status_code = "HTTP_301"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_lb_listener" "server_https" {
|
||||
load_balancer_arn = aws_lb.server.arn
|
||||
port = "443"
|
||||
protocol = "HTTPS"
|
||||
ssl_policy = "ELBSecurityPolicy-2016-08"
|
||||
certificate_arn = aws_acm_certificate.riju.arn
|
||||
|
||||
default_action {
|
||||
type = "forward"
|
||||
target_group_arn = aws_lb_target_group.server.arn
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_autoscaling_attachment" "server" {
|
||||
count = local.ami_available ? 1 : 0
|
||||
|
||||
autoscaling_group_name = aws_autoscaling_group.server[0].name
|
||||
alb_target_group_arn = aws_lb_target_group.server.arn
|
||||
}
|
||||
|
|
|
@ -87,19 +87,14 @@ resource "aws_autoscaling_group" "server" {
|
|||
availability_zones = [
|
||||
for subnet in data.aws_subnet.default : subnet.availability_zone
|
||||
]
|
||||
desired_capacity = 0
|
||||
min_size = 0
|
||||
desired_capacity = 1
|
||||
min_size = 1
|
||||
max_size = 3
|
||||
|
||||
launch_template {
|
||||
id = aws_launch_template.server[0].id
|
||||
}
|
||||
|
||||
target_group_arns = [
|
||||
aws_lb_target_group.server_http.arn,
|
||||
aws_lb_target_group.server_https.arn,
|
||||
]
|
||||
|
||||
tags = concat(
|
||||
[
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue