Skip to content

Commit

Permalink
add DNS, cert and HTTPS
Browse files Browse the repository at this point in the history
  • Loading branch information
ranchodeluxe committed Mar 7, 2023
1 parent 8ca2f88 commit 449193e
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 32 deletions.
32 changes: 32 additions & 0 deletions terraform/veda-wfs3/dns.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
data "aws_route53_zone" "zone" {
provider = aws.west2
name = "delta-backend.com"
}

resource "aws_acm_certificate" "cert" {
domain_name = "*.${data.aws_route53_zone.zone.name}"
validation_method = "DNS"
tags = var.tags

lifecycle {
create_before_destroy = true
}
}

resource "aws_route53_record" "subdomain_record" {
provider = aws.west2
name = "firenrt.${data.aws_route53_zone.zone.name}"
zone_id = data.aws_route53_zone.zone.id
type = "A"

alias {
name = aws_alb.alb_ecs.dns_name
zone_id = aws_alb.alb_ecs.zone_id
evaluate_target_health = true
}
}

resource "aws_lb_listener_certificate" "cert" {
listener_arn = aws_alb_listener.alb_listener_ecs.arn
certificate_arn = aws_acm_certificate.cert.arn
}
5 changes: 5 additions & 0 deletions terraform/veda-wfs3/init.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ provider "aws" {
region = "us-west-1"
}

provider "aws" {
alias = "west2"
region = "us-west-2"
}

terraform {
required_version = "1.3.9"
required_providers {
Expand Down
98 changes: 66 additions & 32 deletions terraform/veda-wfs3/load_balancer.tf
Original file line number Diff line number Diff line change
@@ -1,30 +1,3 @@
resource "aws_alb_target_group" "alb_target_group" {
name = "tf-${var.project_name}-${var.env}-tgroup"
port = var.service_port
protocol = "HTTP"
vpc_id = module.networking.vpc_id
target_type = "ip"
deregistration_delay = 60

lifecycle {
create_before_destroy = true
}

health_check {
interval = 60
path = "/conformance"
port = var.service_port
protocol = "HTTP"
matcher = "200"
timeout = 5
healthy_threshold = 2
unhealthy_threshold = 4
}

depends_on = [
aws_alb.alb_ecs
]
}

/* security group for ALB */
resource "aws_security_group" "web_inbound_sg" {
Expand All @@ -33,8 +6,8 @@ resource "aws_security_group" "web_inbound_sg" {
vpc_id = module.networking.vpc_id

ingress {
from_port = var.service_port
to_port = var.service_port
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
Expand All @@ -58,20 +31,81 @@ resource "aws_security_group" "web_inbound_sg" {
}
}

resource "aws_security_group" "https_web_inbound_sg" {
name = "tf-${var.project_name}-${var.env}-https-web-inbound-sg"
description = "Allow HTTPS from Anywhere into ALB"
vpc_id = module.networking.vpc_id

ingress {
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}

ingress {
from_port = 8
to_port = 8
protocol = "icmp"
cidr_blocks = ["0.0.0.0/0"]
}

egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}

tags = {
Name = "tf-${var.project_name}-${var.env}-https-web-inbound-sg"
}
}

resource "aws_alb" "alb_ecs" {
name = "tf-${var.project_name}-${var.env}-alb"
subnets = module.networking.public_subnets_id
security_groups = concat(module.networking.security_groups_ids, [aws_security_group.web_inbound_sg.id])
security_groups = concat(module.networking.security_groups_ids, [aws_security_group.https_web_inbound_sg.id])

tags = merge({
Name = "tf-${var.project_name}-alb"
}, var.tags)
}

resource "aws_alb_target_group" "alb_target_group" {
name = "tf-${var.project_name}-${var.env}-tgroup"
port = var.service_port
protocol = "HTTP"
vpc_id = module.networking.vpc_id
target_type = "ip"
deregistration_delay = 60

lifecycle {
create_before_destroy = true
}

health_check {
interval = 60
path = "/conformance"
port = var.service_port
protocol = "HTTP"
matcher = "200"
timeout = 5
healthy_threshold = 2
unhealthy_threshold = 4
}

depends_on = [
aws_alb.alb_ecs
]
}

resource "aws_alb_listener" "alb_listener_ecs" {
load_balancer_arn = aws_alb.alb_ecs.arn
port = var.service_port
protocol = "HTTP"
port = 443
protocol = "HTTPS"
ssl_policy = "ELBSecurityPolicy-2016-08"
certificate_arn = aws_acm_certificate.cert.arn
depends_on = [aws_alb_target_group.alb_target_group]

default_action {
Expand Down

0 comments on commit 449193e

Please sign in to comment.