blockscout-terraform/modules/stack/routing.tf

88 lines
2.5 KiB
Terraform
Raw Normal View History

# Create a gateway to provide access to the outside world
resource "aws_internet_gateway" "default" {
vpc_id = "${aws_vpc.vpc.id}"
tags {
prefix = "${var.prefix}"
origin = "terraform"
}
}
# Grant the VPC internet access in its main route table
resource "aws_route" "internet_access" {
route_table_id = "${aws_vpc.vpc.main_route_table_id}"
destination_cidr_block = "0.0.0.0/0"
gateway_id = "${aws_internet_gateway.default.id}"
}
# The ALB for the app server
resource "aws_lb" "explorer" {
2018-09-27 02:55:06 -07:00
count = "${length(var.chains)}"
2018-09-27 02:30:34 -07:00
name = "${var.prefix}-explorer-${element(keys(var.chains),count.index)}-alb"
internal = false
load_balancer_type = "application"
security_groups = ["${aws_security_group.alb.id}"]
subnets = ["${aws_subnet.default.id}", "${aws_subnet.alb.id}"]
enable_deletion_protection = false
tags {
prefix = "${var.prefix}"
origin = "terraform"
}
}
# The Target Group for the ALB
resource "aws_lb_target_group" "explorer" {
2018-09-27 02:30:34 -07:00
count = "${length(var.chains)}"
name = "${var.prefix}-explorer-${element(keys(var.chains),count.index)}-alb-target"
port = 4000
protocol = "HTTP"
vpc_id = "${aws_vpc.vpc.id}"
tags {
prefix = "${var.prefix}"
origin = "terraform"
}
stickiness {
type = "lb_cookie"
cookie_duration = 600
enabled = true
}
health_check {
healthy_threshold = 2
unhealthy_threshold = 2
timeout = 15
interval = 30
2018-10-02 22:31:58 -07:00
path = "/blocks"
port = 4000
}
}
2018-10-18 13:31:29 -07:00
# The Listener for the ALB (HTTP protocol)
resource "aws_alb_listener" "alb_listener_http" {
count = "${var.use_ssl == "true" ? 0 : 1}"
load_balancer_arn = "${aws_lb.explorer.arn}"
port = 80
protocol = "HTTP"
default_action {
type = "forward"
target_group_arn = "${aws_lb_target_group.explorer.arn}"
}
}
# The Listener for the ALB (HTTPS protocol)
resource "aws_alb_listener" "alb_listener_https" {
count = "${var.use_ssl == "true" ? 1 : 0}"
load_balancer_arn = "${aws_lb.explorer.arn}"
port = 443
2018-08-17 06:39:53 -07:00
protocol = "HTTPS"
ssl_policy = "${var.alb_ssl_policy}"
certificate_arn = "${var.alb_certificate_arn}"
2018-09-27 02:55:06 -07:00
default_action {
type = "forward"
target_group_arn = "${aws_lb_target_group.explorer.arn}"
}
}