Skip to content

Commit cfcf340

Browse files
CCM-11056 adding custom DNS (#77)
* CCM-11056 adding custom DNS * CCM-11056 adding custom DNS * CCM-11056 adding custom DNS * CCM-11056 adding custom DNS * CCM-11056 map API and custom domain * CCM-11056 map API and custom domain
1 parent 6caaca7 commit cfcf340

File tree

7 files changed

+60
-1
lines changed

7 files changed

+60
-1
lines changed

.tool-versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
act 0.2.64
22
gitleaks 8.24.0
33
jq 1.6
4-
nodejs 22.11.0
4+
nodejs 22.15.0
55
pre-commit 3.6.0
66
python 3.13.2
77
terraform 1.9.2
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
resource "aws_acm_certificate" "main" {
2+
domain_name = local.root_domain_name
3+
validation_method = "DNS"
4+
5+
lifecycle {
6+
create_before_destroy = true
7+
}
8+
}
9+
10+
resource "aws_acm_certificate_validation" "main" {
11+
certificate_arn = aws_acm_certificate.main.arn
12+
validation_record_fqdns = [for record in aws_route53_record.acm_validation : record.fqdn]
13+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
resource "aws_api_gateway_base_path_mapping" "main" {
2+
api_id = aws_api_gateway_rest_api.main.id
3+
stage_name = aws_api_gateway_stage.main.stage_name
4+
domain_name = aws_api_gateway_domain_name.main.domain_name
5+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
resource "aws_api_gateway_domain_name" "main" {
2+
regional_certificate_arn = aws_acm_certificate_validation.main.certificate_arn
3+
domain_name = local.root_domain_name
4+
security_policy = "TLS_1_2"
5+
6+
endpoint_configuration {
7+
types = ["REGIONAL"]
8+
}
9+
}

infrastructure/terraform/components/api/locals.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
locals {
22
aws_lambda_functions_dir_path = "../../../../lambdas"
3+
root_domain_name = "${var.environment}.${local.acct.route53_zone_names["supplier-api"]}" # e.g. [main|dev|abxy0].supplier-api.[dev|nonprod|prod].nhsnotify.national.nhs.uk
4+
root_domain_id = local.acct.route53_zone_ids["supplier-api"]
5+
root_domain_nameservers = local.acct.route53_zone_nameservers["supplier-api"]
36

47
openapi_spec = templatefile("${path.module}/resources/spec.tmpl.json", {
58
APIG_EXECUTION_ROLE_ARN = aws_iam_role.api_gateway_execution_role.arn
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
resource "aws_route53_record" "main" {
2+
name = aws_api_gateway_domain_name.main.domain_name
3+
type = "A"
4+
zone_id = local.root_domain_id
5+
6+
alias {
7+
name = aws_api_gateway_domain_name.main.regional_domain_name
8+
zone_id = aws_api_gateway_domain_name.main.regional_zone_id
9+
10+
evaluate_target_health = true
11+
}
12+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
resource "aws_route53_record" "acm_validation" {
2+
for_each = {
3+
for dvo in aws_acm_certificate.main.domain_validation_options :
4+
dvo.domain_name => {
5+
name = dvo.resource_record_name
6+
record = dvo.resource_record_value
7+
type = dvo.resource_record_type
8+
} if dvo.domain_name == local.root_domain_name
9+
}
10+
11+
allow_overwrite = true
12+
name = each.value.name
13+
records = [each.value.record]
14+
type = each.value.type
15+
zone_id = local.root_domain_id
16+
ttl = 60
17+
}

0 commit comments

Comments
 (0)