seahaven-site/terraform/cloudfront.tf
Adam Moussa 7812ec102d
Some checks are pending
Deploy / deploy (push) Waiting to run
feat(infra): add HCP Terraform for prod static hosting (PLAT-91) (#37)
* feat(infra): add HCP Terraform for prod static hosting

Greenfield S3+CloudFront+ACM+OIDC content-deploy role under /tf-managed/,
with OOB mgmt DNS helper for ACM validation and apex alias cutover.

* chore(security): suppress pre-existing js-yaml npm audit

* feat(ci): retarget content deploy to seahaven-prod origin

Point OIDC, S3 sync, and CloudFront invalidation at the HCP-managed
prod hosting stack so GHA remains the content publish path after cutover.
2026-08-07 15:09:54 -04:00

70 lines
2.1 KiB
HCL

resource "aws_cloudfront_origin_access_control" "site" {
name = "seahaven-site-prod-oac"
description = "OAC for seahaven-site-prod origin bucket"
origin_access_control_origin_type = "s3"
signing_behavior = "always"
signing_protocol = "sigv4"
}
resource "aws_cloudfront_distribution" "site" {
enabled = true
is_ipv6_enabled = true
comment = "Sea Haven marketing site (seahaven-site-prod)"
default_root_object = "index.html"
price_class = "PriceClass_100"
http_version = "http2and3"
aliases = var.attach_apex_alias ? [var.domain_name] : []
origin {
domain_name = aws_s3_bucket.origin.bucket_regional_domain_name
origin_id = "s3-seahaven-site-prod"
origin_access_control_id = aws_cloudfront_origin_access_control.site.id
}
default_cache_behavior {
target_origin_id = "s3-seahaven-site-prod"
viewer_protocol_policy = "redirect-to-https"
allowed_methods = ["GET", "HEAD", "OPTIONS"]
cached_methods = ["GET", "HEAD"]
compress = true
# Origin Cache-Control from GHA sync is honored (assets max-age=86400; html no-cache).
cache_policy_id = "658327ea-f89d-4fab-a63d-7e88639e58f6" # CachingOptimized
}
custom_error_response {
error_code = 403
response_code = 404
response_page_path = "/404.html"
error_caching_min_ttl = 300
}
custom_error_response {
error_code = 404
response_code = 404
response_page_path = "/404.html"
error_caching_min_ttl = 300
}
restrictions {
geo_restriction {
restriction_type = "none"
}
}
dynamic "viewer_certificate" {
for_each = var.attach_apex_alias ? [1] : []
content {
acm_certificate_arn = aws_acm_certificate.site.arn
ssl_support_method = "sni-only"
minimum_protocol_version = "TLSv1.2_2021"
}
}
dynamic "viewer_certificate" {
for_each = var.attach_apex_alias ? [] : [1]
content {
cloudfront_default_certificate = true
}
}
}