Make ALB listener configurable

This commit is contained in:
natalia 2018-10-18 13:31:29 -07:00
parent e69d47f81c
commit 47366b2aa1
4 changed files with 25 additions and 4 deletions

View File

@ -45,4 +45,5 @@ module "stack" {
alb_ssl_policy = "${var.alb_ssl_policy}"
alb_certificate_arn = "${var.alb_certificate_arn}"
use_ssl = "${var.use_ssl}"
}

View File

@ -162,3 +162,8 @@ variable "alb_certificate_arn" {
description = "The Certificate ARN for the Applicationn Load Balancer Policy"
default = ""
}
variable "use_ssl" {
description = "Enable SSL"
default = "true"
}

View File

@ -58,10 +58,24 @@ resource "aws_lb_target_group" "explorer" {
}
}
# The Listener for the ALB
resource "aws_alb_listener" "alb_listener" {
load_balancer_arn = "${aws_lb.explorer.arn}"
port = 443
# 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
protocol = "HTTPS"
ssl_policy = "${var.alb_ssl_policy}"
certificate_arn = "${var.alb_certificate_arn}"

View File

@ -52,3 +52,4 @@ variable "new_relic_license_key" {}
variable "secret_key_base" {}
variable "alb_ssl_policy" {}
variable "alb_certificate_arn" {}
variable "use_ssl" {}