-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom_domain.tf
60 lines (47 loc) · 1.92 KB
/
custom_domain.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
59
60
resource "aws_apigatewayv2_domain_name" "this" {
count = local.custom_domain ? 1 : 0
domain_name = var.custom_domain_name
domain_name_configuration {
certificate_arn = aws_acm_certificate_validation.validation[0].certificate_arn
endpoint_type = "REGIONAL"
security_policy = "TLS_1_2"
}
}
resource "aws_route53_record" "custom_domain" {
count = local.custom_domain ? 1 : 0
name = aws_apigatewayv2_domain_name.this[0].domain_name
type = "A"
zone_id = var.hosted_zone_id
alias {
name = aws_apigatewayv2_domain_name.this[0].domain_name_configuration[0].target_domain_name
zone_id = aws_apigatewayv2_domain_name.this[0].domain_name_configuration[0].hosted_zone_id
evaluate_target_health = false
}
}
resource "aws_acm_certificate" "custom_domain" {
count = local.custom_domain ? 1 : 0
domain_name = var.custom_domain_name
validation_method = "DNS"
subject_alternative_names = ["*.${var.custom_domain_name}"]
}
resource "aws_route53_record" "validation" {
count = local.custom_domain ? 1 : 0
name = tolist(aws_acm_certificate.custom_domain[0].domain_validation_options)[0].resource_record_name
type = tolist(aws_acm_certificate.custom_domain[0].domain_validation_options)[0].resource_record_type
zone_id = var.hosted_zone_id
records = [tolist(aws_acm_certificate.custom_domain[0].domain_validation_options)[0].resource_record_value]
ttl = "300"
}
resource "aws_acm_certificate_validation" "validation" {
count = local.custom_domain ? 1 : 0
certificate_arn = aws_acm_certificate.custom_domain[0].arn
validation_record_fqdns = [
aws_route53_record.validation[0].fqdn,
]
}
resource "aws_apigatewayv2_api_mapping" "example" {
count = local.custom_domain ? 1 : 0
api_id = aws_apigatewayv2_api.this.id
domain_name = aws_apigatewayv2_domain_name.this[0].id
stage = aws_apigatewayv2_stage.default.id
}