Skip to content

Commit 9f453ba

Browse files
authored
Upgrade Terraform AWS provider to v4.x (#291)
* Rewrite S3 resources * Update external modules * Update deprecated resource * Ensure 4.8 is displayed as minimum version in docs
1 parent d29b104 commit 9f453ba

File tree

12 files changed

+51
-28
lines changed

12 files changed

+51
-28
lines changed

README.md

+1-1
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
}

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
}

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/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"

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)