Model/infrastructure/terraform/modules/cloudfront-api/main.tf
2026-03-12 17:29:47 +00:00

82 lines
No EOL
1.5 KiB
HCL

############################################
# ACM certificate
############################################
resource "aws_acm_certificate" "this" {
domain_name = var.domain_name
validation_method = "DNS"
lifecycle {
create_before_destroy = true
}
}
############################################
# CloudFront distribution
############################################
resource "aws_cloudfront_distribution" "this" {
enabled = true
aliases = [var.domain_name]
origin {
domain_name = var.api_domain_name
origin_id = "api-gateway"
custom_origin_config {
http_port = 80
https_port = 443
origin_protocol_policy = "https-only"
origin_ssl_protocols = ["TLSv1.2"]
}
}
default_cache_behavior {
target_origin_id = "api-gateway"
viewer_protocol_policy = "redirect-to-https"
compress = true
allowed_methods = [
"GET",
"HEAD",
"OPTIONS",
"PUT",
"POST",
"PATCH",
"DELETE"
]
cached_methods = [
"GET",
"HEAD"
]
forwarded_values {
query_string = true
headers = ["*"]
cookies {
forward = "all"
}
}
min_ttl = 0
default_ttl = 0
max_ttl = 0
}
price_class = "PriceClass_100"
restrictions {
geo_restriction {
restriction_type = "none"
}
}
viewer_certificate {
acm_certificate_arn = aws_acm_certificate.this.arn
ssl_support_method = "sni-only"
}
}