Skip to content

Commit 4c31ce9

Browse files
jamengualaknysh
authored andcommitted
Adding lifecycle rule support (#18)
1 parent 594774d commit 4c31ce9

File tree

4 files changed

+90
-4
lines changed

4 files changed

+90
-4
lines changed

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,13 @@ Available targets:
9292
| enabled | Set to `false` to prevent the module from creating any resources | bool | `true` | no |
9393
| 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 |
9494
| 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 |
95+
| lifecycle_rule_enabled | Enable or disable lifecycle rule | bool | `false` | no |
9596
| name | Name (e.g. `app` or `cluster`) | string | - | yes |
9697
| namespace | Namespace (e.g. `eg` or `cp`) | string | `` | no |
98+
| noncurrent_version_expiration_days | Specifies when noncurrent object versions expire | number | `90` | no |
99+
| noncurrent_version_transition_days | Number of days to persist in the standard storage tier before moving to the glacier tier infrequent access tier | number | `30` | no |
97100
| policy | A valid bucket policy JSON document. Note that if the policy document is not specific enough (but still valid), Terraform may view the policy as constantly changing in a terraform plan. In this case, please make sure you use the verbose/specific version of the policy | string | `` | no |
101+
| prefix | Prefix identifying one or more objects to which the rule applies | string | `` | no |
98102
| region | If specified, the AWS region this bucket should reside in. Otherwise, the region used by the callee | string | `` | no |
99103
| sse_algorithm | The server-side encryption algorithm to use. Valid values are `AES256` and `aws:kms` | string | `AES256` | no |
100104
| stage | Stage (e.g. `prod`, `dev`, `staging`) | string | `` | no |
@@ -261,13 +265,13 @@ Check out [our other projects][github], [follow us on twitter][twitter], [apply
261265
|---|---|---|---|
262266

263267
[osterman_homepage]: https://github.com/osterman
264-
[osterman_avatar]: https://github.com/osterman.png?size=150
268+
[osterman_avatar]: https://img.cloudposse.com/150x150/https://github.com/osterman.png
265269
[aknysh_homepage]: https://github.com/aknysh
266-
[aknysh_avatar]: https://github.com/aknysh.png?size=150
270+
[aknysh_avatar]: https://img.cloudposse.com/150x150/https://github.com/aknysh.png
267271
[maximmi_homepage]: https://github.com/maximmi
268-
[maximmi_avatar]: https://github.com/maximmi.png?size=150
272+
[maximmi_avatar]: https://img.cloudposse.com/150x150/https://github.com/maximmi.png
269273
[joshmyers_homepage]: https://github.com/joshmyers
270-
[joshmyers_avatar]: https://github.com/joshmyers.png?size=150
274+
[joshmyers_avatar]: https://img.cloudposse.com/150x150/https://github.com/joshmyers.png
271275

272276

273277

docs/terraform.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
## Inputs
2+
3+
| Name | Description | Type | Default | Required |
4+
|------|-------------|:----:|:-----:|:-----:|
5+
| acl | The canned ACL to apply. We recommend `private` to avoid exposing sensitive information | string | `private` | no |
6+
| allow_encrypted_uploads_only | Set to `true` to prevent uploads of unencrypted objects to S3 bucket | bool | `false` | no |
7+
| allowed_bucket_actions | List of actions the user is permitted to perform on the S3 bucket | list(string) | `<list>` | no |
8+
| attributes | Additional attributes (e.g. `1`) | list(string) | `<list>` | no |
9+
| delimiter | Delimiter to be used between `namespace`, `stage`, `name` and `attributes` | string | `-` | no |
10+
| enabled | Set to `false` to prevent the module from creating any resources | bool | `true` | no |
11+
| 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 |
12+
| 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 |
13+
| lifecycle_rule_enabled | Enable or disable lifecycle rule | bool | `false` | no |
14+
| name | Name (e.g. `app` or `cluster`) | string | - | yes |
15+
| namespace | Namespace (e.g. `eg` or `cp`) | string | `` | no |
16+
| noncurrent_version_expiration_days | Specifies when noncurrent object versions expire | number | `90` | no |
17+
| noncurrent_version_transition_days | Number of days to persist in the standard storage tier before moving to the glacier tier infrequent access tier | number | `30` | no |
18+
| policy | A valid bucket policy JSON document. Note that if the policy document is not specific enough (but still valid), Terraform may view the policy as constantly changing in a terraform plan. In this case, please make sure you use the verbose/specific version of the policy | string | `` | no |
19+
| prefix | Prefix identifying one or more objects to which the rule applies | string | `` | no |
20+
| region | If specified, the AWS region this bucket should reside in. Otherwise, the region used by the callee | string | `` | no |
21+
| sse_algorithm | The server-side encryption algorithm to use. Valid values are `AES256` and `aws:kms` | string | `AES256` | no |
22+
| stage | Stage (e.g. `prod`, `dev`, `staging`) | string | `` | no |
23+
| tags | Additional tags (e.g. `{ BusinessUnit = "XYZ" }` | map(string) | `<map>` | no |
24+
| user_enabled | Set to `true` to create an IAM user with permission to access the bucket | bool | `false` | no |
25+
| versioning_enabled | A state of versioning. Versioning is a means of keeping multiple variants of an object in the same bucket | bool | `false` | no |
26+
27+
## Outputs
28+
29+
| Name | Description |
30+
|------|-------------|
31+
| access_key_id | The access key ID |
32+
| bucket_arn | Bucket ARN |
33+
| bucket_domain_name | FQDN of bucket |
34+
| bucket_id | Bucket Name (aka ID) |
35+
| enabled | Is module enabled |
36+
| secret_access_key | The secret access key. This will be written to the state file in plain-text |
37+
| user_arn | The ARN assigned by AWS for the user |
38+
| user_enabled | Is user creation enabled |
39+
| user_name | Normalized IAM user name |
40+
| user_unique_id | The user unique ID assigned by AWS |
41+

main.tf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,23 @@ resource "aws_s3_bucket" "default" {
2121
enabled = var.versioning_enabled
2222
}
2323

24+
lifecycle_rule {
25+
id = module.default_label.id
26+
enabled = var.lifecycle_rule_enabled
27+
prefix = var.prefix
28+
tags = module.default_label.tags
29+
30+
noncurrent_version_transition {
31+
days = var.noncurrent_version_transition_days
32+
storage_class = "GLACIER"
33+
}
34+
35+
noncurrent_version_expiration {
36+
days = var.noncurrent_version_expiration_days
37+
}
38+
}
39+
40+
2441
# https://docs.aws.amazon.com/AmazonS3/latest/dev/bucket-encryption.html
2542
# https://www.terraform.io/docs/providers/aws/r/s3_bucket.html#enable-default-server-side-encryption
2643
server_side_encryption_configuration {

variables.tf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,27 @@ variable "allow_encrypted_uploads_only" {
9898
default = false
9999
description = "Set to `true` to prevent uploads of unencrypted objects to S3 bucket"
100100
}
101+
102+
variable "lifecycle_rule_enabled" {
103+
type = bool
104+
default = false
105+
description = "Enable or disable lifecycle rule"
106+
}
107+
108+
variable "prefix" {
109+
type = string
110+
default = ""
111+
description = "Prefix identifying one or more objects to which the rule applies"
112+
}
113+
114+
variable "noncurrent_version_transition_days" {
115+
type = number
116+
default = 30
117+
description = "Number of days to persist in the standard storage tier before moving to the glacier tier infrequent access tier"
118+
}
119+
120+
variable "noncurrent_version_expiration_days" {
121+
type = number
122+
default = 90
123+
description = "Specifies when noncurrent object versions expire"
124+
}

0 commit comments

Comments
 (0)