Skip to content

Commit 91384ea

Browse files
committed
refactor module to allow custom cache policy for static assets
1 parent 88d565c commit 91384ea

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

main.tf

+5-4
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ module "assets" {
2424
region = local.aws_region
2525
default_tags = var.default_tags
2626

27-
prefix = "${var.prefix}-assets"
28-
assets_path = "${local.opennext_abs_path}/assets"
29-
cache_path = "${local.opennext_abs_path}/cache"
30-
server_function_role_arn = module.server_function.lambda_role.arn
27+
prefix = "${var.prefix}-assets"
28+
assets_path = "${local.opennext_abs_path}/assets"
29+
cache_path = "${local.opennext_abs_path}/cache"
30+
server_function_role_arn = module.server_function.lambda_role.arn
31+
static_asset_cache_config = var.static_asset_cache_config
3132
}
3233

3334

modules/opennext-assets/s3.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ resource "aws_s3_object" "assets" {
191191
key = "assets/${each.value}"
192192
source = "${var.assets_path}/${each.value}"
193193
source_hash = filemd5("${var.assets_path}/${each.value}")
194-
cache_control = length(regexall(".*(_next).*$", each.value)) > 0 ? "public,max-age=31536000,immutable" : "public,max-age=0,s-maxage=31536000,must-revalidate"
194+
cache_control = length(regexall(".*(_next).*$", each.value)) > 0 ? "public,max-age=31536000,immutable" : var.static_asset_cache_config
195195
content_type = lookup(local.content_type_lookup, split(".", each.value)[length(split(".", each.value)) - 1], "text/plain")
196196
}
197197

modules/opennext-assets/variables.tf

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ variable "cache_path" {
2424
description = "The path of the open-next cache"
2525
}
2626

27+
variable "static_asset_cache_config" {
28+
type = string
29+
description = "Static asset cache config"
30+
}
31+
2732
variable "server_function_role_arn" {
2833
type = string
2934
description = "The IAM role ARN of the Next.js server lambda function"

variables.tf

+9
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ variable "evaluate_target_health" {
4444
description = "Allow Route53 to determine whether to respond to DNS queries by checking the health of the record set"
4545
}
4646

47+
/**
48+
* OpenNext Assets variables
49+
**/
50+
variable "static_asset_cache_config" {
51+
type = string
52+
description = "Static asset cache config"
53+
default = "public,max-age=0,s-maxage=31536000,must-revalidate"
54+
}
55+
4756
/**
4857
* OpenNext Variables
4958
**/

0 commit comments

Comments
 (0)