Skip to content

Commit b867544

Browse files
Add domain name to the api gateway
1 parent be2ba9c commit b867544

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

main.tf

+57
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,60 @@ resource "aws_api_gateway_deployment" "RestApiDeploymentv1" {
270270
rest_api_id = "${aws_api_gateway_rest_api.athauthapi.id}"
271271
stage_name = "v1"
272272
}
273+
274+
resource "aws_acm_certificate" "cert" {
275+
domain_name = "${var.fqdn}"
276+
validation_method = "DNS"
277+
lifecycle {
278+
create_before_destroy = true
279+
}
280+
281+
tags = {
282+
Name = "${var.fqdn}"
283+
ProductDomain = "${local.product_domain}"
284+
Environment = "${var.environment}"
285+
Description = "Certificate for ${var.fqdn}"
286+
ManagedBy = "terraform"
287+
}
288+
}
289+
290+
resource "aws_route53_record" "cert_validation" {
291+
name = "${aws_acm_certificate.cert.domain_validation_options.0.resource_record_name}"
292+
type = "${aws_acm_certificate.cert.domain_validation_options.0.resource_record_type}"
293+
zone_id = "${var.zone_id}"
294+
records = ["${aws_acm_certificate.cert.domain_validation_options.0.resource_record_value}"]
295+
ttl = 60
296+
}
297+
298+
resource "aws_acm_certificate_validation" "athmgmt_domain" {
299+
certificate_arn = "${aws_acm_certificate.cert.arn}"
300+
validation_record_fqdns = ["${aws_route53_record.cert_validation.fqdn}"]
301+
}
302+
303+
resource "aws_api_gateway_domain_name" "athmgmt_domain" {
304+
domain_name = "${var.fqdn}"
305+
regional_certificate_arn = "${aws_acm_certificate_validation.athmgmt_domain.certificate_arn}"
306+
security_policy = "TLS_1_2"
307+
308+
endpoint_configuration {
309+
types = ["REGIONAL"]
310+
}
311+
}
312+
313+
resource "aws_route53_record" "athmgmt_domain" {
314+
name = "${aws_api_gateway_domain_name.athmgmt_domain.domain_name}"
315+
type = "A"
316+
zone_id = "${var.zone_id}"
317+
318+
alias {
319+
evaluate_target_health = true
320+
name = "${aws_api_gateway_domain_name.athmgmt_domain.regional_domain_name}"
321+
zone_id = "${aws_api_gateway_domain_name.athmgmt_domain.regional_zone_id}"
322+
}
323+
}
324+
325+
resource "aws_api_gateway_base_path_mapping" "athmgmt_domain" {
326+
api_id = "${aws_api_gateway_rest_api.athauthapi.id}"
327+
stage_name = "${aws_api_gateway_deployment.RestApiDeploymentv1.stage_name}"
328+
domain_name = "${aws_api_gateway_domain_name.athmgmt_domain.domain_name}"
329+
}

variables.tf

+10
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,13 @@ variable "lambda_timeout" {
231231
type = "string"
232232
description = "The timeout of lambda execution"
233233
}
234+
235+
variable "fqdn" {
236+
type = "string"
237+
description = "FQDN of the api gateway"
238+
}
239+
240+
variable "zone_id" {
241+
type = "string"
242+
description = "Route 53 zone id"
243+
}

0 commit comments

Comments
 (0)