Skip to content

Commit 7ef3167

Browse files
Merge commit '972a5568d474fd3c8531490872251ad5909c028d' into release
2 parents c54bd1f + 972a556 commit 7ef3167

File tree

17 files changed

+69
-34
lines changed

17 files changed

+69
-34
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
## [Unreleased]
44

5+
## [0.12.0] - 2022-04-07
6+
7+
- Ensure compatibility with AWS Provider Version 4 ([#286](https://github.com/milliHQ/terraform-aws-next-js/issues/286), [#291](https://github.com/milliHQ/terraform-aws-next-js/pull/291))
8+
- Add switch for attaching additional policy documents ([#276](https://github.com/milliHQ/terraform-aws-next-js/pull/276))
9+
510
## [0.11.5] - 2022-04-02
611

712
- Adds support for route-manifest v4 ([#292](https://github.com/milliHQ/terraform-aws-next-js/pull/292))

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ terraform {
113113
required_providers {
114114
aws = {
115115
source = "hashicorp/aws"
116-
version = "~> 3.0"
116+
version = "~> 4.0"
117117
}
118118
}
119119
}
@@ -199,13 +199,13 @@ You can create a `.terraformignore` in the root of your project and add the foll
199199
| Name | Version |
200200
|------|---------|
201201
| terraform | >= 0.15 |
202-
| aws | >= 3.64.0 |
202+
| aws | >= 4.8 |
203203

204204
## Providers
205205

206206
| Name | Version |
207207
|------|---------|
208-
| aws | >= 3.64.0 |
208+
| aws | >= 4.8 |
209209

210210
## Inputs
211211

@@ -227,6 +227,7 @@ You can create a `.terraformignore` in the root of your project and add the foll
227227
| deployment\_name | Identifier for the deployment group (only lowercase alphanumeric characters and hyphens are allowed). | `string` | `"tf-next"` | no |
228228
| expire\_static\_assets | Number of days after which static assets from previous deployments should be removed from S3. Set to -1 to disable expiration. | `number` | `30` | no |
229229
| image\_optimization\_lambda\_memory\_size | Amount of memory in MB the worker Lambda Function for image optimization can use. Valid value between 128 MB to 10,240 MB, in 1 MB increments. | `number` | `2048` | no |
230+
| lambda\_attach\_policy\_json | Whether to deploy additional lambda JSON policies. If false, lambda\_policy\_json will not be attached to the lambda function. (Necessary since policy strings are only known after apply when using Terraforms data.aws\_iam\_policy\_document) | `bool` | `false` | no |
230231
| lambda\_attach\_to\_vpc | Set to true if the Lambda functions should be attached to a VPC. Use this setting if VPC resources should be accessed by the Lambda functions. When setting this to true, use vpc\_security\_group\_ids and vpc\_subnet\_ids to specify the VPC networking. Note that attaching to a VPC would introduce a delay on to cold starts | `bool` | `false` | no |
231232
| lambda\_environment\_variables | Map that defines environment variables for the Lambda Functions in Next.js. | `map(string)` | `{}` | no |
232233
| lambda\_memory\_size | Amount of memory in MB a Lambda Function can use at runtime. Valid value between 128 MB to 10,240 MB, in 1 MB increments. | `number` | `1024` | no |

examples/complete/main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ terraform {
22
required_providers {
33
aws = {
44
source = "hashicorp/aws"
5-
version = "~> 3.0"
5+
version = "~> 4.0"
66
}
77
}
88
}

examples/next-image/main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ terraform {
22
required_providers {
33
aws = {
44
source = "hashicorp/aws"
5-
version = "~> 3.0"
5+
version = "~> 4.0"
66
}
77
}
88
}

examples/static/main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ terraform {
22
required_providers {
33
aws = {
44
source = "hashicorp/aws"
5-
version = "~> 3.0"
5+
version = "~> 4.0"
66
}
77
}
88
}

examples/with-custom-domain/main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ terraform {
22
required_providers {
33
aws = {
44
source = "hashicorp/aws"
5-
version = "~> 3.0"
5+
version = "~> 4.0"
66
}
77
}
88
}

examples/with-existing-cloudfront/main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ terraform {
22
required_providers {
33
aws = {
44
source = "hashicorp/aws"
5-
version = "~> 3.0"
5+
version = "~> 4.0"
66
}
77
}
88
}

iam.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ resource "aws_iam_role_policy_attachment" "lambda_vpc" {
8383
####################################
8484

8585
resource "aws_iam_policy" "additional_json" {
86-
count = var.lambda_policy_json != null ? 1 : 0
86+
count = var.lambda_attach_policy_json ? 1 : 0
8787

8888
description = "Managed by Terraform Next.js"
8989
policy = var.lambda_policy_json
@@ -92,7 +92,7 @@ resource "aws_iam_policy" "additional_json" {
9292
}
9393

9494
resource "aws_iam_role_policy_attachment" "additional_json" {
95-
for_each = var.lambda_policy_json != null ? local.lambdas : {}
95+
for_each = var.lambda_attach_policy_json ? local.lambdas : {}
9696

9797
role = aws_iam_role.lambda[each.key].name
9898
policy_arn = aws_iam_policy.additional_json[0].arn

main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ module "next_image" {
148148
count = var.create_image_optimization ? 1 : 0
149149

150150
source = "milliHQ/next-js-image-optimization/aws"
151-
version = "~> 12.0.10"
151+
version = ">= 12.1.0"
152152

153153
cloudfront_create_distribution = false
154154

modules/cloudfront-proxy-config/main.tf

+6-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@ locals {
1010

1111
resource "aws_s3_bucket" "proxy_config_store" {
1212
bucket_prefix = "${var.deployment_name}-tfn-config"
13-
acl = "private"
1413
force_destroy = true
1514
tags = merge(var.tags, var.tags_s3_bucket)
1615
}
1716

17+
resource "aws_s3_bucket_acl" "proxy_config_store" {
18+
bucket = aws_s3_bucket.proxy_config_store.id
19+
acl = "private"
20+
}
21+
1822
data "aws_iam_policy_document" "cf_access" {
1923
statement {
2024
actions = ["s3:GetObject"]
@@ -36,7 +40,7 @@ resource "aws_s3_bucket_policy" "proxy_config_store_origin_access" {
3640
# Upload Proxy Config
3741
#####################
3842

39-
resource "aws_s3_bucket_object" "config_json" {
43+
resource "aws_s3_object" "config_json" {
4044
bucket = aws_s3_bucket.proxy_config_store.id
4145
key = local.proxy_config_key
4246
content = var.proxy_config_json

modules/cloudfront-proxy-config/versions.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 3.0"
7+
version = ">= 4.0"
88
}
99
}
1010
}

modules/proxy/main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module "proxy_package" {
1515

1616
module "edge_proxy" {
1717
source = "terraform-aws-modules/lambda/aws"
18-
version = "2.4.0"
18+
version = "3.1.0"
1919

2020
lambda_at_edge = true
2121

modules/proxy/variables.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
variable "proxy_module_version" {
66
type = string
7-
default = "0.11.5"
7+
default = "0.12.0"
88
}
99

1010
variable "lambda_default_runtime" {

modules/statics-deploy/main.tf

+35-16
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,24 @@ locals {
99

1010
resource "aws_s3_bucket" "static_upload" {
1111
bucket_prefix = "${var.deployment_name}-tfn-deploy"
12-
acl = "private"
1312
force_destroy = true
1413

15-
# We are using versioning here to ensure that no file gets overridden at upload
16-
versioning {
17-
enabled = true
18-
}
19-
2014
tags = merge(var.tags, var.tags_s3_bucket)
2115
}
2216

17+
resource "aws_s3_bucket_acl" "static_upload" {
18+
bucket = aws_s3_bucket.static_upload.id
19+
acl = "private"
20+
}
21+
22+
# We are using versioning here to ensure that no file gets overridden at upload
23+
resource "aws_s3_bucket_versioning" "static_upload" {
24+
bucket = aws_s3_bucket.static_upload.id
25+
versioning_configuration {
26+
status = "Enabled"
27+
}
28+
}
29+
2330
resource "aws_s3_bucket_notification" "on_create" {
2431
bucket = aws_s3_bucket.static_upload.id
2532

@@ -35,23 +42,35 @@ resource "aws_s3_bucket_notification" "on_create" {
3542

3643
resource "aws_s3_bucket" "static_deploy" {
3744
bucket_prefix = "${var.deployment_name}-tfn-static"
38-
acl = "private"
3945
force_destroy = true
4046

41-
lifecycle_rule {
42-
id = "Expire static assets"
43-
enabled = var.expire_static_assets >= 0 # -1 disables the cleanup
47+
tags = merge(var.tags, var.tags_s3_bucket)
48+
}
49+
50+
resource "aws_s3_bucket_acl" "static_deploy" {
51+
bucket = aws_s3_bucket.static_deploy.id
52+
acl = "private"
53+
}
54+
55+
resource "aws_s3_bucket_lifecycle_configuration" "static_deploy" {
56+
bucket = aws_s3_bucket.static_deploy.id
4457

45-
tags = {
46-
"tfnextExpire" = "true"
47-
}
58+
rule {
59+
id = "Expire static assets"
4860

4961
expiration {
5062
days = var.expire_static_assets > 0 ? var.expire_static_assets : 0
5163
}
52-
}
5364

54-
tags = merge(var.tags, var.tags_s3_bucket)
65+
filter {
66+
tag {
67+
key = "tfnextExpire"
68+
value = "true"
69+
}
70+
}
71+
72+
status = var.expire_static_assets >= 0 ? "Enabled" : "Disabled" # -1 disables the cleanup
73+
}
5574
}
5675

5776
# CloudFront permissions for the bucket
@@ -172,7 +191,7 @@ module "lambda_content" {
172191

173192
module "deploy_trigger" {
174193
source = "terraform-aws-modules/lambda/aws"
175-
version = "2.4.0"
194+
version = "3.1.0"
176195

177196
function_name = "${var.deployment_name}_tfn-deploy"
178197
description = "Managed by Terraform Next.js"

modules/statics-deploy/variables.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ variable "static_files_archive" {
44

55
variable "deploy_trigger_module_version" {
66
type = string
7-
default = "0.11.5"
7+
default = "0.12.0"
88
}
99

1010
variable "expire_static_assets" {

variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ variable "lambda_policy_json" {
6464
default = null
6565
}
6666

67+
variable "lambda_attach_policy_json" {
68+
description = "Whether to deploy additional lambda JSON policies. If false, lambda_policy_json will not be attached to the lambda function. (Necessary since policy strings are only known after apply when using Terraforms data.aws_iam_policy_document)"
69+
type = bool
70+
default = false
71+
}
72+
6773
variable "lambda_role_permissions_boundary" {
6874
type = string
6975
# https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_boundaries.html

versions.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 3.64.0"
7+
version = ">= 4.8"
88
configuration_aliases = [aws.global_region]
99
}
1010
}

0 commit comments

Comments
 (0)