-
Notifications
You must be signed in to change notification settings - Fork 1
/
ssl.tf
58 lines (48 loc) · 1.95 KB
/
ssl.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* Copyright 2020 Quortex
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
# There are 2 options for specifying a TLS certificate for the Load Balancer:
# - specify the ARN of an already existing and validated certificate
# - create the certificate ourselves in AWS Certificate Manager, and validate it.
# The resources below are used in the latter case.
# Certificate in AWS Certificate Manager
resource "aws_acm_certificate" "cert" {
count = var.ssl_certificate_arn == null ? 1 : 0
domain_name = var.ssl_certificate_domain_name
validation_method = "DNS"
tags = merge({
Name = local.ssl_certificate_name
},
var.tags
)
lifecycle {
create_before_destroy = true
}
}
# DNS record to validate this certificate
resource "aws_route53_record" "cert_validation" {
count = var.ssl_certificate_arn == null ? 1 : 0
name = tolist(aws_acm_certificate.cert[0].domain_validation_options).0.resource_record_name
type = tolist(aws_acm_certificate.cert[0].domain_validation_options).0.resource_record_type
zone_id = data.aws_route53_zone.selected[0].zone_id
records = [tolist(aws_acm_certificate.cert[0].domain_validation_options).0.resource_record_value]
ttl = 60
}
# Certificate validation
resource "aws_acm_certificate_validation" "cert" {
count = var.ssl_certificate_arn == null ? 1 : 0
certificate_arn = aws_acm_certificate.cert[0].arn
validation_record_fqdns = [aws_route53_record.cert_validation[0].fqdn]
}