diff --git a/CHANGELOG.md b/CHANGELOG.md index 5820030..cd75d7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## [Unreleased] +## [12.1.0] - 2022-04-04 + +- Ensure compatibility with AWS Provider Version 4 ([#119](https://github.com/milliHQ/terraform-aws-next-js-image-optimization/pull/119), [#120](https://github.com/milliHQ/terraform-aws-next-js-image-optimization/issues/120)) +- Uses Image Optimizer module of [Next.js 12.1.0](https://github.com/vercel/next.js/releases/tag/v12.1.0) ([#123](https://github.com/milliHQ/terraform-aws-next-js-image-optimization/pull/123)) +- Adds option to enable SVG support ([#124](https://github.com/milliHQ/terraform-aws-next-js-image-optimization/pull/124)) + ## [12.0.10] - 2022-03-29 - Updates sharp from `v0.30.1` to [`v0.30.3`](https://github.com/lovell/sharp/releases/tag/v0.30.3) ([#115](https://github.com/milliHQ/terraform-aws-next-js-image-optimization/pull/115)) diff --git a/README.md b/README.md index 9cb2b20..313f2ac 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ terraform { required_providers { aws = { source = "hashicorp/aws" - version = "~> 3.0" + version = "~> 4.0" } } } @@ -111,13 +111,13 @@ Then rebuild and redeploy your Next.js application to make use of the changed co | Name | Version | |------|---------| | terraform | >= 0.13 | -| aws | >= 3.43.0 | +| aws | >= 4.8 | ## Providers | Name | Version | |------|---------| -| aws | >= 3.43.0 | +| aws | >= 4.8 | ## Inputs @@ -136,11 +136,13 @@ Then rebuild and redeploy your Next.js application to make use of the changed co | lambda\_role\_permissions\_boundary | ARN of IAM policy that scopes aws\_iam\_role access for the lambda. | `string` | `null` | no | | lambda\_timeout | Max amount of time the worker Lambda Function has to return a response in seconds. Should not be more than 30 (Limited by API Gateway). | `number` | `30` | no | | next\_image\_base\_origin | Base URL where requests for absolute image paths should be resolved to. Should not have a trailing slash. | `string` | `null` | no | +| next\_image\_content\_security\_policy | Set the value of the Content-Security-Policy header in the response of the image optimizer. | `string` | `null` | no | +| next\_image\_dangerously\_allow\_SVG | Enable the optimization of SVG images. | `bool` | `false` | no | | next\_image\_device\_sizes | Allowed device sizes that should be used for image optimization. | `list(number)` | `null` | no | | next\_image\_domains | Allowed origin domains that can be used for fetching images. | `list(string)` | `[]` | no | | next\_image\_formats | If the Accept head matches more than one of the configured formats, the first match in the array is used. Therefore, the array order matters. If there is no match, the Image Optimization API will fallback to the original image's format. | `list(string)` |
[| no | | next\_image\_image\_sizes | Allowed image sizes that should be used for image optimization. | `list(number)` | `null` | no | -| next\_image\_version | Next.js version from where you want to use the image optimizer from. Supports semver ranges. | `string` | `"12.0.10"` | no | +| next\_image\_version | Next.js version from where you want to use the image optimizer from. Supports semver ranges. | `string` | `"12.1.0"` | no | | source\_bucket\_id | When your static files are deployed to a Bucket (e.g. with Terraform Next.js) the optimizer can pull the source from the bucket rather than over the internet. | `string` | `null` | no | | tags | Tag metadata to label AWS resources that support tags. | `map(string)` | `{}` | no | diff --git a/docs/assets/architecture.png b/docs/assets/architecture.png index 64228f7..183b689 100644 Binary files a/docs/assets/architecture.png and b/docs/assets/architecture.png differ diff --git a/examples/with-existing-cloudfront/main.tf b/examples/with-existing-cloudfront/main.tf index 6d47ec8..b77fea5 100644 --- a/examples/with-existing-cloudfront/main.tf +++ b/examples/with-existing-cloudfront/main.tf @@ -2,7 +2,7 @@ terraform { required_providers { aws = { source = "hashicorp/aws" - version = "~> 3.0" + version = "~> 4.0" } } } diff --git a/examples/with-next-js-export/main.tf b/examples/with-next-js-export/main.tf index 2f8a428..94e7ec4 100644 --- a/examples/with-next-js-export/main.tf +++ b/examples/with-next-js-export/main.tf @@ -2,7 +2,7 @@ terraform { required_providers { aws = { source = "hashicorp/aws" - version = "~> 3.0" + version = "~> 4.0" } } } @@ -40,23 +40,38 @@ module "next_image_optimizer" { ########### resource "aws_s3_bucket" "website_bucket" { bucket_prefix = var.deployment_name - acl = "public-read" force_destroy = true + tags = { + Name = var.deployment_name + } +} + +resource "aws_s3_bucket_acl" "website_bucket" { + bucket = aws_s3_bucket.website_bucket.id + acl = "public-read" +} + +resource "aws_s3_bucket_cors_configuration" "website_bucket" { + bucket = aws_s3_bucket.website_bucket.id + cors_rule { allowed_headers = ["Authorization", "Content-Length"] allowed_methods = ["GET", "POST"] allowed_origins = ["*"] max_age_seconds = 3000 } +} - website { - index_document = "index.html" - error_document = "404/index.html" +resource "aws_s3_bucket_website_configuration" "website_bucket" { + bucket = aws_s3_bucket.website_bucket.id + + index_document { + suffix = "index.html" } - tags = { - Name = var.deployment_name + error_document { + key = "404/index.html" } } @@ -106,7 +121,7 @@ resource "aws_cloudfront_distribution" "distribution" { } origin { - domain_name = aws_s3_bucket.website_bucket.website_endpoint + domain_name = aws_s3_bucket_website_configuration.website_bucket.website_endpoint origin_id = "website-bucket" custom_origin_config { diff --git a/examples/with-next-js/README.md b/examples/with-next-js/README.md index b89dcf5..40faf6e 100644 --- a/examples/with-next-js/README.md +++ b/examples/with-next-js/README.md @@ -15,7 +15,7 @@ terraform { required_providers { aws = { source = "hashicorp/aws" - version = "~> 3.0" + version = "~> 4.0" } } } diff --git a/main.tf b/main.tf index 6398d1b..0b65598 100644 --- a/main.tf +++ b/main.tf @@ -15,7 +15,7 @@ module "lambda_content" { module "image_optimizer" { source = "terraform-aws-modules/lambda/aws" - version = "2.17.0" + version = "3.1.0" function_name = var.deployment_name description = "Managed by Terraform Next.js image optimizer" @@ -26,13 +26,15 @@ module "image_optimizer" { publish = true environment_variables = { - NODE_ENV = "production" - TF_NEXTIMAGE_BASE_ORIGIN = var.next_image_base_origin - TF_NEXTIMAGE_DOMAINS = jsonencode(var.next_image_domains) - TF_NEXTIMAGE_DEVICE_SIZES = var.next_image_device_sizes != null ? jsonencode(var.next_image_device_sizes) : null - TF_NEXTIMAGE_FORMATS = jsonencode(var.next_image_formats) - TF_NEXTIMAGE_IMAGE_SIZES = var.next_image_image_sizes != null ? jsonencode(var.next_image_image_sizes) : null - TF_NEXTIMAGE_SOURCE_BUCKET = var.source_bucket_id + NODE_ENV = "production" + TF_NEXTIMAGE_BASE_ORIGIN = var.next_image_base_origin + TF_NEXTIMAGE_DOMAINS = jsonencode(var.next_image_domains) + TF_NEXTIMAGE_DEVICE_SIZES = var.next_image_device_sizes != null ? jsonencode(var.next_image_device_sizes) : null + TF_NEXTIMAGE_FORMATS = jsonencode(var.next_image_formats) + TF_NEXTIMAGE_IMAGE_SIZES = var.next_image_image_sizes != null ? jsonencode(var.next_image_image_sizes) : null + TF_NEXTIMAGE_DANGEROUSLY_ALLOW_SVG = var.next_image_dangerously_allow_SVG ? jsonencode(var.next_image_dangerously_allow_SVG) : null + TF_NEXTIMAGE_CONTENT_SECURITY_POLICY = var.next_image_content_security_policy != null ? jsonencode(var.next_image_content_security_policy) : null + TF_NEXTIMAGE_SOURCE_BUCKET = var.source_bucket_id } create_package = false diff --git a/variables.tf b/variables.tf index 4a7c285..bd172a0 100644 --- a/variables.tf +++ b/variables.tf @@ -4,7 +4,7 @@ variable "next_image_version" { description = "Next.js version from where you want to use the image optimizer from. Supports semver ranges." type = string - default = "12.0.10" + default = "12.1.0" } variable "next_image_base_origin" { @@ -37,6 +37,18 @@ variable "next_image_image_sizes" { default = null } +variable "next_image_dangerously_allow_SVG" { + description = "Enable the optimization of SVG images." + type = bool + default = false +} + +variable "next_image_content_security_policy" { + description = "Set the value of the Content-Security-Policy header in the response of the image optimizer." + type = string + default = null +} + variable "lambda_memory_size" { description = "Amount of memory in MB the worker Lambda Function can use. Valid value between 128 MB to 10,240 MB, in 1 MB increments." type = number diff --git a/versions.tf b/versions.tf index 66ac1a4..76a08cd 100644 --- a/versions.tf +++ b/versions.tf @@ -4,7 +4,7 @@ terraform { required_providers { aws = { source = "hashicorp/aws" - version = ">= 3.43.0" + version = ">= 4.8" } } }
"image/webp"
]