diff --git a/main.tf b/main.tf index 1f44aa8..d3e732c 100644 --- a/main.tf +++ b/main.tf @@ -24,10 +24,11 @@ module "assets" { region = local.aws_region default_tags = var.default_tags - prefix = "${var.prefix}-assets" - assets_path = "${local.opennext_abs_path}/assets" - cache_path = "${local.opennext_abs_path}/cache" - server_function_role_arn = module.server_function.lambda_role.arn + prefix = "${var.prefix}-assets" + assets_path = "${local.opennext_abs_path}/assets" + cache_path = "${local.opennext_abs_path}/cache" + server_function_role_arn = module.server_function.lambda_role.arn + static_asset_cache_config = var.static_asset_cache_config } diff --git a/modules/opennext-assets/s3.tf b/modules/opennext-assets/s3.tf index 5146639..ec8b71a 100644 --- a/modules/opennext-assets/s3.tf +++ b/modules/opennext-assets/s3.tf @@ -191,7 +191,7 @@ resource "aws_s3_object" "assets" { key = "assets/${each.value}" source = "${var.assets_path}/${each.value}" source_hash = filemd5("${var.assets_path}/${each.value}") - cache_control = length(regexall(".*(_next).*$", each.value)) > 0 ? "public,max-age=31536000,immutable" : "public,max-age=0,s-maxage=31536000,must-revalidate" + cache_control = length(regexall(".*(_next).*$", each.value)) > 0 ? "public,max-age=31536000,immutable" : var.static_asset_cache_config content_type = lookup(local.content_type_lookup, split(".", each.value)[length(split(".", each.value)) - 1], "text/plain") } diff --git a/modules/opennext-assets/variables.tf b/modules/opennext-assets/variables.tf index ff701de..4dc0e33 100644 --- a/modules/opennext-assets/variables.tf +++ b/modules/opennext-assets/variables.tf @@ -29,6 +29,11 @@ variable "server_function_role_arn" { description = "The IAM role ARN of the Next.js server lambda function" } +variable "static_asset_cache_config" { + type = string + description = "Static asset cache config" +} + variable "logging_config" { type = object({ target_bucket = string diff --git a/modules/opennext-cloudfront/cloudfront.tf b/modules/opennext-cloudfront/cloudfront.tf index e4f755d..23f2f45 100644 --- a/modules/opennext-cloudfront/cloudfront.tf +++ b/modules/opennext-cloudfront/cloudfront.tf @@ -163,7 +163,7 @@ resource "aws_cloudfront_response_headers_policy" "response_headers_policy" { resource "aws_cloudfront_distribution" "distribution" { provider = aws.global - price_class = "PriceClass_100" + price_class = var.price_class enabled = true is_ipv6_enabled = true comment = coalesce(var.comment, "${var.prefix} - CloudFront Distribution for Next.js Application") @@ -174,7 +174,7 @@ resource "aws_cloudfront_distribution" "distribution" { include_cookies = false # bucket = module.cloudfront_logs.logs_s3_bucket.bucket_regional_domain_name bucket = var.logging_bucket_domain_name - prefix = one(var.aliases) + prefix = length(var.aliases) > 0 ? var.aliases[0] : null } viewer_certificate { diff --git a/variables.tf b/variables.tf index 1b73f07..6cebad7 100644 --- a/variables.tf +++ b/variables.tf @@ -44,6 +44,15 @@ variable "evaluate_target_health" { description = "Allow Route53 to determine whether to respond to DNS queries by checking the health of the record set" } +/** + * OpenNext Assets variables +**/ +variable "static_asset_cache_config" { + type = string + description = "Static asset cache config" + default = "public,max-age=0,s-maxage=31536000,must-revalidate" +} + /** * OpenNext Variables **/