Skip to content

Commit 8650aab

Browse files
author
Steven Nemetz
committed
Support multiple SSL certificates on first HTTPS port listener
1 parent fa5327c commit 8650aab

File tree

7 files changed

+207
-1
lines changed

7 files changed

+207
-1
lines changed

examples/https-multi-certs/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# ALB using HTTPS with multiple SSL certificates

examples/https-multi-certs/main.tf

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
data "aws_vpc" "vpc" {
2+
tags {
3+
Env = "one"
4+
}
5+
}
6+
7+
# Look up security group
8+
data "aws_subnet_ids" "public_subnet_ids" {
9+
vpc_id = "${data.aws_vpc.vpc.id}"
10+
11+
tags {
12+
Network = "Public"
13+
}
14+
}
15+
16+
data "aws_subnet_ids" "private_subnet_ids" {
17+
vpc_id = "${data.aws_vpc.vpc.id}"
18+
19+
tags {
20+
Network = "Private"
21+
}
22+
}
23+
24+
#
25+
module "lb-https" {
26+
source = "../../"
27+
name = "lb-https-multi"
28+
environment = "one"
29+
organization = "wiser"
30+
certificate_additional_names = ["*.one.wiser.com", "*.test.wiser.com"]
31+
certificate_name = "*.wiser.com"
32+
instance_http_ports = ""
33+
instance_https_ports = "443,8443"
34+
instance_tcp_ports = ""
35+
internal = false # PUBLIC
36+
lb_http_ports = ""
37+
lb_https_ports = "443,8443"
38+
lb_protocols = ["HTTPS"]
39+
lb_tcp_ports = ""
40+
ports = "3000,4000"
41+
security_groups = ["sg-bef0a5c2"] # PUBLIC -> use whitelist SG
42+
subnets = "${data.aws_subnet_ids.public_subnet_ids.ids}" # PUBLIC -> use public subnets
43+
vpc_id = "${data.aws_vpc.vpc.id}"
44+
}

examples/https-multi-certs/outputs.tf

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
//
2+
// LB attributes
3+
//
4+
output "arn" {
5+
description = "ARN of the LB itself. Useful for debug output, for example when attaching a WAF."
6+
value = "${module.lb-https.arn}"
7+
}
8+
9+
output "dns_name" {
10+
description = "The DNS name of the LB presumably to be used with a friendlier CNAME."
11+
value = "${module.lb-https.dns_name}"
12+
}
13+
14+
output "id" {
15+
description = "The ID of the LB we created."
16+
value = "${module.lb-https.id}"
17+
}
18+
19+
output "zone_id" {
20+
description = "The zone_id of the LB to assist with creating DNS records."
21+
value = "${module.lb-https.zone_id}"
22+
}
23+
24+
# arn_suffix
25+
# canonical_hosted_zone_id
26+
27+
//
28+
// LB Listener attributes
29+
//
30+
output "listener_http_arns" {
31+
description = "The ARNs of the HTTP LB Listeners"
32+
value = "${module.lb-https.listener_http_arns}"
33+
}
34+
35+
output "listener_http_ids" {
36+
description = "The IDs of the HTTP LB Listeners"
37+
value = "${module.lb-https.listener_http_ids}"
38+
}
39+
40+
output "listener_https_arns" {
41+
description = "The ARNs of the HTTPS LB Listeners"
42+
value = "${module.lb-https.listener_https_arns}"
43+
}
44+
45+
output "listener_https_ids" {
46+
description = "The IDs of the HTTPS LB Listeners"
47+
value = "${module.lb-https.listener_https_ids}"
48+
}
49+
50+
output "listener_tcp_arns" {
51+
description = "The ARNs of the network TCP LB Listeners"
52+
value = "${module.lb-https.listener_tcp_arns}"
53+
}
54+
55+
output "listener_tcp_ids" {
56+
description = "The IDs of the network TCP LB Listeners"
57+
value = "${module.lb-https.listener_tcp_ids}"
58+
}
59+
60+
output "listener_arns" {
61+
description = "ARNs of all the LB Listeners"
62+
value = "${module.lb-https.listener_arns}"
63+
}
64+
65+
output "listener_ids" {
66+
description = "IDs of all the LB Listeners"
67+
value = "${module.lb-https.listener_ids}"
68+
}
69+
70+
//
71+
// LB Target Group attributes
72+
//
73+
output "target_group_http_arns" {
74+
description = "ARNs of the HTTP target groups. Useful for passing to your Auto Scaling group module."
75+
value = "${module.lb-https.target_group_http_arns}"
76+
}
77+
78+
output "target_group_https_arns" {
79+
description = "ARNs of the HTTPS target groups. Useful for passing to your Auto Scaling group module."
80+
value = "${module.lb-https.target_group_https_arns}"
81+
}
82+
83+
output "target_group_tcp_arns" {
84+
description = "ARNs of the TCP target groups. Useful for passing to your Auto Scaling group module."
85+
value = "${module.lb-https.target_group_tcp_arns}"
86+
}
87+
88+
output "target_group_arns" {
89+
description = "ARNs of all the target groups. Useful for passing to your Auto Scaling group module."
90+
value = "${module.lb-https.target_group_arns}"
91+
}
92+
93+
output "target_group_http_ids" {
94+
description = "IDs of the HTTP target groups"
95+
value = "${module.lb-https.target_group_http_ids}"
96+
}
97+
98+
output "target_group_https_ids" {
99+
description = "IDs of the HTTPS target groups"
100+
value = "${module.lb-https.target_group_https_ids}"
101+
}
102+
103+
output "target_group_tcp_ids" {
104+
description = "IDs of the TCP target groups"
105+
value = "${module.lb-https.target_group_tcp_ids}"
106+
}
107+
108+
output "target_group_ids" {
109+
description = "IDs of all the target groups"
110+
value = "${module.lb-https.target_group_ids}"
111+
}
112+
113+
# arn_suffix
114+
# name
115+
116+
//
117+
// Misc
118+
//
119+
output "principal_account_id" {
120+
description = "The AWS-owned account given permissions to write your LB logs to S3."
121+
value = "${module.lb-https.principal_account_id}"
122+
}
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
provider "aws" {
2+
region = "${var.region}"
3+
4+
#version = "1.5"
5+
}
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
variable "region" {
2+
default = "us-west-2"
3+
}

main.tf

+25
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ data "aws_acm_certificate" "this" {
8080
#statuses = ["ISSUED"]
8181
}
8282

83+
data "aws_acm_certificate" "additional" {
84+
count = "${
85+
module.enabled.value &&
86+
var.type == "application" &&
87+
contains(var.lb_protocols, "HTTPS")
88+
? length(var.certificate_additional_names) : 0
89+
}"
90+
91+
domain = "${var.certificate_additional_names[count.index]}"
92+
}
93+
8394
# May need to create 2: 1 w/ logs and 1 w/o logs
8495
resource "aws_lb" "application" {
8596
count = "${module.enabled.value && var.type == "application" ? 1 : 0}"
@@ -394,6 +405,20 @@ resource "aws_lb_listener" "https" {
394405
}
395406
}
396407

408+
# Additional certs for https listener on first port
409+
# TODO: figure out way to add to all ports
410+
# temp: could add another stansa for second port if >= 2 https ports
411+
resource "aws_lb_listener_certificate" "https" {
412+
count = "${
413+
module.enabled.value &&
414+
var.type == "application" &&
415+
contains(var.lb_protocols, "HTTPS")
416+
? length(var.certificate_additional_names) : 0 }"
417+
418+
listener_arn = "${element(aws_lb_listener.https.*.arn, 0)}"
419+
certificate_arn = "${element(data.aws_acm_certificate.additional.*.arn, count.index)}"
420+
}
421+
397422
resource "aws_lb_listener" "network" {
398423
count = "${
399424
module.enabled.value &&

variables.tf

+7-1
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,14 @@ variable "enable_logging" {
5858
default = false
5959
}
6060

61+
variable "certificate_additional_names" {
62+
description = "List of additional names of SSL Certificates to look up in ACM and use"
63+
type = "list"
64+
default = []
65+
}
66+
6167
variable "certificate_name" {
62-
description = "The name of the SSL Certificate to look up in ACM and use"
68+
description = "The name of the default SSL Certificate to look up in ACM and use"
6369
default = ""
6470
}
6571

0 commit comments

Comments
 (0)