From 619e699d5cf2283a441b7095b4fcca4342fb4706 Mon Sep 17 00:00:00 2001 From: Brian Helba Date: Wed, 6 Apr 2022 18:32:53 -0400 Subject: [PATCH] Upgrade AWS provider to a new major release --- examples/basic/.terraform.lock.hcl | 27 +++++++++-------- modules/storage/main.tf | 48 +++++++++++++++++++++--------- modules/storage/versions.tf | 5 +++- 3 files changed, 52 insertions(+), 28 deletions(-) diff --git a/examples/basic/.terraform.lock.hcl b/examples/basic/.terraform.lock.hcl index 48aed58..38ebdb3 100644 --- a/examples/basic/.terraform.lock.hcl +++ b/examples/basic/.terraform.lock.hcl @@ -2,20 +2,21 @@ # Manual edits may be lost in future updates. provider "registry.terraform.io/hashicorp/aws" { - version = "3.46.0" + version = "4.28.0" hashes = [ - "h1:sNDpXH+7Ay7efB1MSdd5Pb5WL/Ww5EHvLFsqCD5ceD0=", - "zh:3ec89dba1d9ed494c5a8069b98d230289c736f5d7abb0d47d6d657d1c9a22a38", - "zh:47dd0ba54897a43aa22a9009d9eddec30d2e656a6153219335af23c5be609e47", - "zh:482164d6d7782d574d6ef3740d02a3b3566c9e3f03021b497675aa4aa6855ef9", - "zh:5b068dd406e0989cb1b1ce390b8dc33eb77997a594b500dea3d39595e67086b3", - "zh:7bb6dbe99cd483db05d28e0e3109dac6be233961f816b1145035f0f49b30bbde", - "zh:7c245831b5e062b0207b988821d6ed674516c78b81afe0fc015a58e40b973d05", - "zh:7f3fb2457ff59c6e3795acd0995cb3ec3b0f22fce5ab8b261e8480bc752787a6", - "zh:8dcbb64802f38dc20fccedaf93dbfbf367859eba81fe7fa4dc734323f287cf4a", - "zh:da6c412927a514e46ff81e4044ce29617b7c11d33db99ff959a761f97ca09fce", - "zh:e670cda0e9ffcd791d94bb1822c26e2a1d26cb0e7a7b655019f4375a14e04e90", - "zh:ebf9c5ef3eceebc1c21bcd31e535e5c323c3bf6ca5918959e297e9a6617d8094", + "h1:TXCUuuaf2q54C43bxSNiF9g+cxTr8zqEZem0pW15cjE=", + "zh:1d4806e50971d2cd565273cedf3206e38931677a6f546cf2b9fb140b52b80604", + "zh:3f076791002b8afa5ba2d2038f1e1db5956022327eb5242152723ed410ae4571", + "zh:40e5944a9df0d083dbd316bcc6ac9ceada5c00dab70c21897e62b68c4c936bc9", + "zh:68b78d0c1866aa0bcbbadb1cf51349c9af697f8789f5778b7e7e2912a9c4845d", + "zh:72d6e66136841c0e5ae264e03555cf59751ddae1b9784eafcb877c624332c70a", + "zh:902c8f89dc10d321b87c09270c27a31a42d4e74e4da1608e55b7f241cd010a62", + "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", + "zh:bf54c9f55d420b4e1fe68db81a759c40b9f9747159dea3061212a1c9768dcdfd", + "zh:bfbe7e745c420a4ebd27ca35dfe5c2acc7cdd05092e1daf60f5ae29a1130d752", + "zh:d271a30b16f0861f020e423d120d1458cf1757e740e016ace22084c39dc13550", + "zh:f1e4672d1625fd1f1268d4b807cb90e28150d46fb2d0dd0836de65db29c8d5e6", + "zh:f5cee910b4db2da3c2a28dae9055cbca4273eb774c362bb7bb5bde04deff4557", ] } diff --git a/modules/storage/main.tf b/modules/storage/main.tf index fe611c1..bb5c41e 100644 --- a/modules/storage/main.tf +++ b/modules/storage/main.tf @@ -1,21 +1,14 @@ resource "aws_s3_bucket" "storage" { bucket = var.bucket_name - acl = "private" - policy = data.aws_iam_policy_document.storage_bucket.json +} - // Encrypt with an Amazon-managed key - server_side_encryption_configuration { - rule { - apply_server_side_encryption_by_default { - sse_algorithm = "AES256" - } - } - } +resource "aws_s3_bucket_acl" "storage" { + bucket = aws_s3_bucket.storage.id + acl = "private" +} - lifecycle_rule { - enabled = true - abort_incomplete_multipart_upload_days = 7 - } +resource "aws_s3_bucket_cors_configuration" "storage" { + bucket = aws_s3_bucket.storage.id cors_rule { allowed_headers = ["*"] @@ -61,6 +54,33 @@ resource "aws_s3_bucket" "storage" { } } +resource "aws_s3_bucket_lifecycle_configuration" "storage" { + bucket = aws_s3_bucket.storage.id + + rule { + id = "abort-incomplete-multipart-upload" + status = "Enabled" + abort_incomplete_multipart_upload { + days_after_initiation = 7 + } + } +} + +resource "aws_s3_bucket_server_side_encryption_configuration" "storage" { + bucket = aws_s3_bucket.storage.id + + // Encrypt with an Amazon-managed key + rule { + apply_server_side_encryption_by_default { + sse_algorithm = "AES256" + } + } +} + +resource "aws_s3_bucket_policy" "storage" { + bucket = aws_s3_bucket.storage.id + policy = data.aws_iam_policy_document.storage_bucket.json +} data "aws_iam_policy_document" "storage_bucket" { statement { diff --git a/modules/storage/versions.tf b/modules/storage/versions.tf index 85515ab..cf99e5d 100644 --- a/modules/storage/versions.tf +++ b/modules/storage/versions.tf @@ -3,7 +3,10 @@ terraform { required_providers { aws = { - source = "hashicorp/aws" + source = "hashicorp/aws" + # 4.9 includes backwards-compatible aws_s3_bucket syntax, + # which makes globally upgrading the aws provider easier + version = ">= 4.9.0" } } }