Skip to content

Commit fe66c46

Browse files
jamengualPePe (Jose) Amengual
andauthored
adding dynamics to allow for other expiration types (#21)
* adding dynamic to allow for other expiration types for non versioned buckets * adding support for abort_incomplete_multipart_upload_days * Fixing tags in lifecycle when multipart upload is enabled Co-authored-by: PePe (Jose) Amengual <[email protected]>
1 parent 444f956 commit fe66c46

File tree

4 files changed

+87
-9
lines changed

4 files changed

+87
-9
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,21 @@ Available targets:
123123

124124
| Name | Description | Type | Default | Required |
125125
|------|-------------|:----:|:-----:|:-----:|
126+
| abort_incomplete_multipart_upload_days | Maximum time (in days) that you want to allow multipart uploads to remain in progress | number | `5` | no |
126127
| acl | The canned ACL to apply. We recommend `private` to avoid exposing sensitive information | string | `private` | no |
127128
| allow_encrypted_uploads_only | Set to `true` to prevent uploads of unencrypted objects to S3 bucket | bool | `false` | no |
128129
| allowed_bucket_actions | List of actions the user is permitted to perform on the S3 bucket | list(string) | `<list>` | no |
129130
| attributes | Additional attributes (e.g. `1`) | list(string) | `<list>` | no |
130131
| delimiter | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes` | string | `-` | no |
132+
| enable_glacier_transition | Enables the transition to AWS Glacier which can cause unnecessary costs for huge amount of small files | bool | `true` | no |
131133
| enabled | Set to false to prevent the module from creating any resources | bool | `true` | no |
132134
| environment | Environment, e.g. 'prod', 'staging', 'dev', 'pre-prod', 'UAT' | string | `` | no |
135+
| expiration_days | Number of days after which to expunge the objects | number | `90` | no |
133136
| force_destroy | A boolean string that indicates all objects should be deleted from the bucket so that the bucket can be destroyed without error. These objects are not recoverable | bool | `false` | no |
137+
| glacier_transition_days | Number of days after which to move the data to the glacier storage tier | number | `60` | no |
134138
| kms_master_key_arn | The AWS KMS master key ARN used for the `SSE-KMS` encryption. This can only be used when you set the value of `sse_algorithm` as `aws:kms`. The default aws/s3 AWS KMS master key is used if this element is absent while the `sse_algorithm` is `aws:kms` | string | `` | no |
135139
| lifecycle_rule_enabled | Enable or disable lifecycle rule | bool | `false` | no |
140+
| lifecycle_tags | Tags filter. Used to manage object lifecycle events | map(string) | `<map>` | no |
136141
| name | Solution name, e.g. 'app' or 'jenkins' | string | `` | no |
137142
| namespace | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | string | `` | no |
138143
| noncurrent_version_expiration_days | Specifies when noncurrent object versions expire | number | `90` | no |
@@ -142,6 +147,7 @@ Available targets:
142147
| region | If specified, the AWS region this bucket should reside in. Otherwise, the region used by the callee | string | `` | no |
143148
| sse_algorithm | The server-side encryption algorithm to use. Valid values are `AES256` and `aws:kms` | string | `AES256` | no |
144149
| stage | Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release' | string | `` | no |
150+
| standard_transition_days | Number of days to persist in the standard storage tier before moving to the infrequent access tier | number | `30` | no |
145151
| tags | Additional tags (e.g. `map('BusinessUnit','XYZ')` | map(string) | `<map>` | no |
146152
| user_enabled | Set to `true` to create an IAM user with permission to access the bucket | bool | `false` | no |
147153
| versioning_enabled | A state of versioning. Versioning is a means of keeping multiple variants of an object in the same bucket | bool | `false` | no |
@@ -218,6 +224,10 @@ We deliver 10x the value for a fraction of the cost of a full-time engineer. Our
218224

219225
Join our [Open Source Community][slack] on Slack. It's **FREE** for everyone! Our "SweetOps" community is where you get to talk with others who share a similar vision for how to rollout and manage infrastructure. This is the best place to talk shop, ask questions, solicit feedback, and work together as a community to build totally *sweet* infrastructure.
220226

227+
## Discourse Forums
228+
229+
Participate in our [Discourse Forums][discourse]. Here you'll find answers to commonly asked questions. Most questions will be related to the enormous number of projects we support on our GitHub. Come here to collaborate on answers, find solutions, and get ideas about the products and services we value. It only takes a minute to get started! Just sign in with SSO using your GitHub account.
230+
221231
## Newsletter
222232

223233
Sign up for [our newsletter][newsletter] that covers everything on our technology radar. Receive updates on what we're up to on GitHub as well as awesome new projects we discover.
@@ -333,6 +343,7 @@ Check out [our other projects][github], [follow us on twitter][twitter], [apply
333343
[testimonial]: https://cpco.io/leave-testimonial?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-s3-bucket&utm_content=testimonial
334344
[office_hours]: https://cloudposse.com/office-hours?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-s3-bucket&utm_content=office_hours
335345
[newsletter]: https://cpco.io/newsletter?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-s3-bucket&utm_content=newsletter
346+
[discourse]: https://ask.sweetops.com/?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-s3-bucket&utm_content=discourse
336347
[email]: https://cpco.io/email?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-s3-bucket&utm_content=email
337348
[commercial_support]: https://cpco.io/commercial-support?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-s3-bucket&utm_content=commercial_support
338349
[we_love_open_source]: https://cpco.io/we-love-open-source?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-s3-bucket&utm_content=we_love_open_source

docs/terraform.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,21 @@
22

33
| Name | Description | Type | Default | Required |
44
|------|-------------|:----:|:-----:|:-----:|
5+
| abort_incomplete_multipart_upload_days | Maximum time (in days) that you want to allow multipart uploads to remain in progress | number | `5` | no |
56
| acl | The canned ACL to apply. We recommend `private` to avoid exposing sensitive information | string | `private` | no |
67
| allow_encrypted_uploads_only | Set to `true` to prevent uploads of unencrypted objects to S3 bucket | bool | `false` | no |
78
| allowed_bucket_actions | List of actions the user is permitted to perform on the S3 bucket | list(string) | `<list>` | no |
89
| attributes | Additional attributes (e.g. `1`) | list(string) | `<list>` | no |
910
| delimiter | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes` | string | `-` | no |
11+
| enable_glacier_transition | Enables the transition to AWS Glacier which can cause unnecessary costs for huge amount of small files | bool | `true` | no |
1012
| enabled | Set to false to prevent the module from creating any resources | bool | `true` | no |
1113
| environment | Environment, e.g. 'prod', 'staging', 'dev', 'pre-prod', 'UAT' | string | `` | no |
14+
| expiration_days | Number of days after which to expunge the objects | number | `90` | no |
1215
| force_destroy | A boolean string that indicates all objects should be deleted from the bucket so that the bucket can be destroyed without error. These objects are not recoverable | bool | `false` | no |
16+
| glacier_transition_days | Number of days after which to move the data to the glacier storage tier | number | `60` | no |
1317
| kms_master_key_arn | The AWS KMS master key ARN used for the `SSE-KMS` encryption. This can only be used when you set the value of `sse_algorithm` as `aws:kms`. The default aws/s3 AWS KMS master key is used if this element is absent while the `sse_algorithm` is `aws:kms` | string | `` | no |
1418
| lifecycle_rule_enabled | Enable or disable lifecycle rule | bool | `false` | no |
19+
| lifecycle_tags | Tags filter. Used to manage object lifecycle events | map(string) | `<map>` | no |
1520
| name | Solution name, e.g. 'app' or 'jenkins' | string | `` | no |
1621
| namespace | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | string | `` | no |
1722
| noncurrent_version_expiration_days | Specifies when noncurrent object versions expire | number | `90` | no |
@@ -21,6 +26,7 @@
2126
| region | If specified, the AWS region this bucket should reside in. Otherwise, the region used by the callee | string | `` | no |
2227
| sse_algorithm | The server-side encryption algorithm to use. Valid values are `AES256` and `aws:kms` | string | `AES256` | no |
2328
| stage | Stage, e.g. 'prod', 'staging', 'dev', OR 'source', 'build', 'test', 'deploy', 'release' | string | `` | no |
29+
| standard_transition_days | Number of days to persist in the standard storage tier before moving to the infrequent access tier | number | `30` | no |
2430
| tags | Additional tags (e.g. `map('BusinessUnit','XYZ')` | map(string) | `<map>` | no |
2531
| user_enabled | Set to `true` to create an IAM user with permission to access the bucket | bool | `false` | no |
2632
| versioning_enabled | A state of versioning. Versioning is a means of keeping multiple variants of an object in the same bucket | bool | `false` | no |

main.tf

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,43 @@ resource "aws_s3_bucket" "default" {
2323
}
2424

2525
lifecycle_rule {
26-
id = module.label.id
27-
enabled = var.lifecycle_rule_enabled
28-
prefix = var.prefix
29-
tags = module.label.tags
30-
31-
noncurrent_version_transition {
32-
days = var.noncurrent_version_transition_days
33-
storage_class = "GLACIER"
34-
}
26+
id = module.label.id
27+
enabled = var.lifecycle_rule_enabled
28+
prefix = var.prefix
29+
tags = var.lifecycle_tags
30+
abort_incomplete_multipart_upload_days = var.abort_incomplete_multipart_upload_days
3531

3632
noncurrent_version_expiration {
3733
days = var.noncurrent_version_expiration_days
3834
}
35+
36+
dynamic "noncurrent_version_transition" {
37+
for_each = var.enable_glacier_transition ? [1] : []
38+
39+
content {
40+
days = var.noncurrent_version_transition_days
41+
storage_class = "GLACIER"
42+
}
43+
}
44+
45+
transition {
46+
days = var.standard_transition_days
47+
storage_class = "STANDARD_IA"
48+
}
49+
50+
dynamic "transition" {
51+
for_each = var.enable_glacier_transition ? [1] : []
52+
53+
content {
54+
days = var.glacier_transition_days
55+
storage_class = "GLACIER"
56+
}
57+
}
58+
59+
expiration {
60+
days = var.expiration_days
61+
}
62+
3963
}
4064

4165
# https://docs.aws.amazon.com/AmazonS3/latest/dev/bucket-encryption.html

variables.tf

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,40 @@ variable "noncurrent_version_expiration_days" {
129129
default = 90
130130
description = "Specifies when noncurrent object versions expire"
131131
}
132+
133+
variable "standard_transition_days" {
134+
type = number
135+
default = 30
136+
description = "Number of days to persist in the standard storage tier before moving to the infrequent access tier"
137+
}
138+
139+
variable "glacier_transition_days" {
140+
type = number
141+
default = 60
142+
description = "Number of days after which to move the data to the glacier storage tier"
143+
}
144+
145+
variable "enable_glacier_transition" {
146+
type = bool
147+
default = true
148+
description = "Enables the transition to AWS Glacier which can cause unnecessary costs for huge amount of small files"
149+
}
150+
151+
variable "expiration_days" {
152+
type = number
153+
default = 90
154+
description = "Number of days after which to expunge the objects"
155+
}
156+
157+
variable "abort_incomplete_multipart_upload_days" {
158+
type = number
159+
default = 5
160+
description = "Maximum time (in days) that you want to allow multipart uploads to remain in progress"
161+
}
162+
163+
variable "lifecycle_tags" {
164+
type = map(string)
165+
description = "Tags filter. Used to manage object lifecycle events"
166+
default = {}
167+
}
168+

0 commit comments

Comments
 (0)