Skip to content

Commit 190c3c2

Browse files
ryankingczimergebot
authored andcommitted
[feature] lifecycle policy for s3 buckets (#156)
[feature] lifecycle policy for s3 bucketsS3 buckets will now have a lifecycle policy that does a few things 1. incomplete multipart uploads will be aborted after 14 days [doc](https://docs.aws.amazon.com/AmazonS3/latest/dev/mpuoverview.html#mpu-abort-incomplete-mpu-lifecycle-config) 2. non-current versions will be moved to infrequent-access storage after 30 days 3. non-current versions will be deleted after 365 days The test for this module is also changed from just 'init' to doing an apply. ### Test Plan * newly updated unit test ### References * https://docs.aws.amazon.com/AmazonS3/latest/dev/mpuoverview.html#mpu-abort-incomplete-mpu-lifecycle-config
1 parent 0b06a76 commit 190c3c2

File tree

4 files changed

+51
-5
lines changed

4 files changed

+51
-5
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ check-docs:
5959
.PHONY: check-docs
6060

6161
clean:
62-
rm **/*.tfstate*; true
62+
rm **/*.tfstate*; true
6363
.PHONY: clean
6464

6565
test: fmt

aws-s3-private-bucket/main.tf

+21
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,27 @@ resource "aws_s3_bucket" "bucket" {
1818
enabled = var.enable_versioning
1919
}
2020

21+
lifecycle_rule {
22+
enabled = true
23+
24+
abort_incomplete_multipart_upload_days = var.abort_incomplete_multipart_upload_days
25+
26+
expiration {
27+
expired_object_delete_marker = true
28+
}
29+
30+
noncurrent_version_transition {
31+
days = 30
32+
storage_class = "STANDARD_IA"
33+
}
34+
35+
noncurrent_version_expiration {
36+
days = 365
37+
}
38+
}
39+
40+
41+
2142
# TODO
2243
# logging {
2344
# target_bucket = ""

aws-s3-private-bucket/module_test.go

+23-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,31 @@ package test
33
import (
44
"testing"
55

6+
"github.com/chanzuckerberg/cztack/testutil"
67
"github.com/gruntwork-io/terratest/modules/terraform"
78
)
89

910
func TestPrivateBucket(t *testing.T) {
10-
options := &terraform.Options{
11-
TerraformDir: ".",
12-
}
13-
terraform.Init(t, options)
11+
12+
project := testutil.UniqueId()
13+
env := testutil.UniqueId()
14+
service := testutil.UniqueId()
15+
owner := testutil.UniqueId()
16+
17+
bucketName := testutil.UniqueId()
18+
19+
options := testutil.Options(
20+
testutil.DefaultRegion,
21+
map[string]interface{}{
22+
"project": project,
23+
"env": env,
24+
"service": service,
25+
"owner": owner,
26+
27+
"bucket_name": bucketName,
28+
},
29+
)
30+
31+
defer terraform.Destroy(t, options)
32+
testutil.Run(t, options)
1433
}

aws-s3-private-bucket/variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,9 @@ variable "enable_versioning" {
2828
description = "Keep old versions of overwritten S3 objects."
2929
default = true
3030
}
31+
32+
variable "abort_incomplete_multipart_upload_days" {
33+
type = number
34+
description = "Number of days after which an incomplete multipart upload is canceled."
35+
default = 14
36+
}

0 commit comments

Comments
 (0)