Skip to content

Commit

Permalink
Deprecating hostname and path parameters and allowing empty hostnames
Browse files Browse the repository at this point in the history
  • Loading branch information
adenot committed Aug 4, 2020
1 parent b0c9bf8 commit b4a97c9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 32 deletions.
12 changes: 1 addition & 11 deletions _variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ variable "cpu" {
description = "Hard limit for CPU for the container"
}

variable "path" {
default = "/*"
description = "Optional path to use on listener rule"
}

variable "paths" {
default = []
description = "List of path to use on listener rule"
Expand All @@ -42,14 +37,9 @@ variable "hostname_create" {
description = "Optional parameter to create or not a Route53 record"
}

variable "hostname" {
default = ""
description = "Hostname to create DNS record for this app (DEPRECATED - use hostnames)"
}

variable "hostnames" {
default = []
description = "List of hostnames to create DNS record for this app"
description = "List of hostnames to create listerner rule and optionally, DNS records for this app"
}

variable "hostname_redirects" {
Expand Down
38 changes: 25 additions & 13 deletions alb-target-group.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@ resource "aws_lb_listener_rule" "green" {
target_group_arn = aws_lb_target_group.green.arn
}

condition {
path_pattern {
values = length(var.paths) > 0 ? var.paths : list(var.path)
dynamic "condition" {
for_each = length(var.paths) > 0 ? [var.paths] : []
content {
path_pattern {
values = toset(condition.value)
}
}
}

condition {
host_header {
values = var.hostname != "" ? list(var.hostname) : var.hostnames
dynamic "condition" {
for_each = length(var.hostnames) > 0 ? [var.hostnames] : []
content {
host_header {
values = toset(condition.value)
}
}
}

Expand All @@ -35,15 +41,21 @@ resource "aws_lb_listener_rule" "blue" {
target_group_arn = aws_lb_target_group.blue.arn
}

condition {
path_pattern {
values = length(var.paths) > 0 ? var.paths : list(var.path)
dynamic "condition" {
for_each = length(var.paths) > 0 ? [var.paths] : []
content {
path_pattern {
values = toset(condition.value)
}
}
}

condition {
host_header {
values = var.hostname != "" ? list(var.hostname) : var.hostnames
dynamic "condition" {
for_each = length(var.hostnames) > 0 ? [var.hostnames] : []
content {
host_header {
values = toset(condition.value)
}
}
}

Expand All @@ -64,7 +76,7 @@ resource "aws_lb_listener_rule" "redirects" {
type = "redirect"

redirect {
host = var.hostname != "" ? var.hostname : var.hostnames[0]
host = var.hostnames[0]
port = "443"
protocol = "HTTPS"
status_code = "HTTP_301"
Expand Down
8 changes: 0 additions & 8 deletions route53-record.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@ data "aws_route53_zone" "selected" {
name = var.hosted_zone
}

resource "aws_route53_record" "hostname" {
count = var.alb_only && var.hostname_create && var.hostname != "" ? 1 : 0
zone_id = data.aws_route53_zone.selected.*.zone_id[0]
name = var.hostname
type = "CNAME"
ttl = "300"
records = list(var.alb_dns_name)
}
resource "aws_route53_record" "hostnames" {
count = var.alb_only && var.hostname_create && length(var.hostnames) != 0 ? length(var.hostnames) : 0
zone_id = data.aws_route53_zone.selected.*.zone_id[0]
Expand Down

0 comments on commit b4a97c9

Please sign in to comment.