Skip to content

Commit

Permalink
Add changes from PR 20 by @andylamp
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomdango committed Feb 18, 2024
1 parent f8e81a7 commit a00d591
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
9 changes: 5 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}


Expand Down
2 changes: 1 addition & 1 deletion modules/opennext-assets/s3.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
5 changes: 5 additions & 0 deletions modules/opennext-assets/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions modules/opennext-cloudfront/cloudfront.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
**/
Expand Down

0 comments on commit a00d591

Please sign in to comment.