File tree Expand file tree Collapse file tree 6 files changed +71
-2
lines changed
Expand file tree Collapse file tree 6 files changed +71
-2
lines changed Original file line number Diff line number Diff line change 1+ resource "aws_acm_certificate" "main" {
2+ domain_name = local. mtls_api_gateway_full_domain_name
3+ validation_method = " DNS"
4+
5+ lifecycle {
6+ create_before_destroy = true
7+ }
8+ }
9+
10+ # Record used by ACM for DNS Validation
11+ resource "aws_route53_record" "validation" {
12+ for_each = {
13+ for dvo in aws_acm_certificate . main . domain_validation_options : dvo . domain_name => {
14+ name = dvo.resource_record_name
15+ record = dvo.resource_record_value
16+ type = dvo.resource_record_type
17+ }
18+ }
19+
20+ allow_overwrite = true
21+ name = each. value . name
22+ records = [each . value . record ]
23+ ttl = 60
24+ type = each. value . type
25+ zone_id = module. route53_mtls_api . zone_id
26+ }
27+
28+
29+ resource "aws_acm_certificate_validation" "main" {
30+ certificate_arn = aws_acm_certificate. main . arn
31+ validation_record_fqdns = [for record in aws_route53_record . validation : record . fqdn ]
32+ }
Original file line number Diff line number Diff line change @@ -13,15 +13,15 @@ resource "aws_api_gateway_rest_api" "mtls_doc_store_api" {
1313
1414resource "aws_api_gateway_domain_name" "mtls_custom_api_domain" {
1515 domain_name = local. mtls_api_gateway_full_domain_name
16- regional_certificate_arn = module . ndr-ecs-fargate-app . certificate_arn
16+ regional_certificate_arn = aws_acm_certificate_validation . main . certificate_arn
1717 security_policy = " TLS_1_2"
1818
1919 endpoint_configuration {
2020 types = [" REGIONAL" ]
2121 }
2222
2323 mutual_tls_authentication {
24- truststore_uri = " s3://${ module . s3bucket_truststore . bucket_id } "
24+ truststore_uri = " s3://${ module . s3bucket_truststore . bucket_id } / ${ var . ca_pem_filename } "
2525 }
2626}
2727
Original file line number Diff line number Diff line change @@ -126,6 +126,12 @@ module "s3bucket_truststore" {
126126 owner = var. owner
127127}
128128
129+ # Certificate for MTLS
130+ data "aws_s3_object" "truststore_ext_cert" {
131+ bucket = module. s3bucket_truststore . bucket_id
132+ key = var. ca_pem_filename
133+ }
134+
129135# Lifecycle Rules
130136resource "aws_s3_bucket_lifecycle_configuration" "lg-lifecycle-rules" {
131137 bucket = module. ndr-lloyd-george-store . bucket_id
Original file line number Diff line number Diff line change @@ -10,3 +10,15 @@ module "route53_fargate_ui" {
1010 api_gateway_full_domain_name = aws_api_gateway_domain_name. custom_api_domain . regional_domain_name
1111 api_gateway_zone_id = aws_api_gateway_domain_name. custom_api_domain . regional_zone_id
1212}
13+
14+ module "route53_mtls_api" {
15+ source = " ./modules/route53"
16+ environment = var. environment
17+ owner = var. owner
18+ domain = var. domain
19+ using_arf_hosted_zone = true
20+ dns_name = local. mtls_api_gateway_subdomain_name
21+ api_gateway_subdomain_name = local. mtls_api_gateway_subdomain_name
22+ api_gateway_full_domain_name = aws_api_gateway_domain_name. mtls_custom_api_domain . regional_domain_name
23+ api_gateway_zone_id = aws_api_gateway_domain_name. mtls_custom_api_domain . regional_zone_id
24+ }
Original file line number Diff line number Diff line change 1+ # A record for API Gateway Custom Domain Name
2+ resource "aws_route53_record" "pdm_api" {
3+ name = aws_api_gateway_domain_name. mtls_custom_api_domain . domain_name
4+ type = " A"
5+ zone_id = module. route53_mtls_api . zone_id
6+
7+ alias {
8+ name = aws_api_gateway_domain_name. mtls_custom_api_domain . regional_domain_name
9+ zone_id = aws_api_gateway_domain_name. mtls_custom_api_domain . regional_zone_id
10+ evaluate_target_health = true
11+ }
12+ }
Original file line number Diff line number Diff line change @@ -63,6 +63,12 @@ variable "trustore_bucket_name" {
6363 default = " truststore"
6464}
6565
66+ variable "ca_pem_filename" {
67+ type = string
68+ description = " Filename of the CA Truststore pem file stored in the core Truststore s3 bucket"
69+ default = " nhs-main-ndr-truststore.pem"
70+ }
71+
6672# DynamoDB Table Variables
6773
6874variable "pdm_dynamodb_table_name" {
@@ -218,6 +224,7 @@ locals {
218224
219225 api_gateway_subdomain_name = contains ([" prod" ], terraform. workspace ) ? " ${ var . certificate_subdomain_name_prefix } " : " ${ var . certificate_subdomain_name_prefix } ${ terraform . workspace } "
220226 api_gateway_full_domain_name = contains ([" prod" ], terraform. workspace ) ? " ${ var . certificate_subdomain_name_prefix } ${ var . domain } " : " ${ var . certificate_subdomain_name_prefix } ${ terraform . workspace } .${ var . domain } "
227+ mtls_api_gateway_subdomain_name = contains ([" prod" ], terraform. workspace ) ? " mtls.${ var . certificate_subdomain_name_prefix } " : " mtls.${ var . certificate_subdomain_name_prefix } ${ terraform . workspace } "
221228 mtls_api_gateway_full_domain_name = contains ([" prod" ], terraform. workspace ) ? " mtls.${ var . domain } " : " mtls.${ terraform . workspace } .${ var . domain } "
222229
223230
You can’t perform that action at this time.
0 commit comments