Skip to content

Commit c499981

Browse files
committed
feat: add object_lock_configuration support
Add S3 Object Lock pass-through support to the cloudtrail-s3-bucket module. This enables compliance requirements like PCI by allowing WORM (write-once-read-many) protection on CloudTrail logs. Object Lock must be enabled at bucket creation time and requires versioning (enabled by default).
1 parent e85282f commit c499981

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ The module supports the following:
4343
1. Forced [server-side encryption](https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingServerSideEncryption.html) at rest for the S3 bucket
4444
2. S3 bucket [versioning](https://docs.aws.amazon.com/AmazonS3/latest/dev/Versioning.html) to easily recover from both unintended user actions and application failures
4545
3. S3 bucket is protected from deletion if it's not empty ([force_destroy](https://www.terraform.io/docs/providers/aws/r/s3_bucket.html#force_destroy) set to `false`)
46+
4. [S3 Object Lock](https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lock.html) for WORM (write-once-read-many) protection, useful for compliance requirements (e.g., PCI)
4647

4748

4849
> [!TIP]
@@ -73,6 +74,29 @@ module "s3_bucket" {
7374
}
7475
```
7576

77+
### With S3 Object Lock (for compliance)
78+
79+
S3 Object Lock can only be enabled at bucket creation time and requires versioning (enabled by default).
80+
81+
```hcl
82+
module "s3_bucket" {
83+
source = "cloudposse/cloudtrail-s3-bucket/aws"
84+
# Cloud Posse recommends pinning every module to a specific version
85+
# version = "x.x.x"
86+
namespace = "eg"
87+
stage = "prod"
88+
name = "cluster"
89+
90+
versioning_enabled = true
91+
92+
object_lock_configuration = {
93+
mode = "GOVERNANCE"
94+
days = 365
95+
years = null
96+
}
97+
}
98+
```
99+
76100
> [!IMPORTANT]
77101
> In Cloud Posse's examples, we avoid pinning modules to specific versions to prevent discrepancies between the documentation
78102
> and the latest released versions. However, for your own projects, we strongly advise pinning each module to the exact version
@@ -155,6 +179,7 @@ module "s3_bucket" {
155179
| <a name="input_namespace"></a> [namespace](#input\_namespace) | ID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally unique | `string` | `null` | no |
156180
| <a name="input_noncurrent_version_expiration_days"></a> [noncurrent\_version\_expiration\_days](#input\_noncurrent\_version\_expiration\_days) | Specifies when noncurrent object versions expire | `number` | `90` | no |
157181
| <a name="input_noncurrent_version_transition_days"></a> [noncurrent\_version\_transition\_days](#input\_noncurrent\_version\_transition\_days) | Specifies when noncurrent object versions transitions | `number` | `30` | no |
182+
| <a name="input_object_lock_configuration"></a> [object\_lock\_configuration](#input\_object\_lock\_configuration) | A configuration for S3 object locking. With S3 Object Lock, you can store objects using a write-once-read-many (WORM) model. Object Lock can help prevent objects from being deleted or overwritten for a fixed amount of time or indefinitely. | <pre>object({<br/> mode = string # Valid values are GOVERNANCE and COMPLIANCE.<br/> days = number<br/> years = number<br/> })</pre> | `null` | no |
158183
| <a name="input_policy"></a> [policy](#input\_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 |
159184
| <a name="input_regex_replace_chars"></a> [regex\_replace\_chars](#input\_regex\_replace\_chars) | Terraform regular expression (regex) string.<br/>Characters matching the regex will be removed from the ID elements.<br/>If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no |
160185
| <a name="input_restrict_public_buckets"></a> [restrict\_public\_buckets](#input\_restrict\_public\_buckets) | Set to `false` to disable the restricting of making the bucket public | `bool` | `true` | no |

README.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ description: |-
5757
1. Forced [server-side encryption](https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingServerSideEncryption.html) at rest for the S3 bucket
5858
2. S3 bucket [versioning](https://docs.aws.amazon.com/AmazonS3/latest/dev/Versioning.html) to easily recover from both unintended user actions and application failures
5959
3. S3 bucket is protected from deletion if it's not empty ([force_destroy](https://www.terraform.io/docs/providers/aws/r/s3_bucket.html#force_destroy) set to `false`)
60+
4. [S3 Object Lock](https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lock.html) for WORM (write-once-read-many) protection, useful for compliance requirements (e.g., PCI)
6061
6162
# How to use this project
6263
usage: |-
@@ -71,5 +72,28 @@ usage: |-
7172
}
7273
```
7374
75+
### With S3 Object Lock (for compliance)
76+
77+
S3 Object Lock can only be enabled at bucket creation time and requires versioning (enabled by default).
78+
79+
```hcl
80+
module "s3_bucket" {
81+
source = "cloudposse/cloudtrail-s3-bucket/aws"
82+
# Cloud Posse recommends pinning every module to a specific version
83+
# version = "x.x.x"
84+
namespace = "eg"
85+
stage = "prod"
86+
name = "cluster"
87+
88+
versioning_enabled = true
89+
90+
object_lock_configuration = {
91+
mode = "GOVERNANCE"
92+
days = 365
93+
years = null
94+
}
95+
}
96+
```
97+
7498
include: []
7599
contributors: []

main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module "s3_bucket" {
2929
bucket_notifications_enabled = var.bucket_notifications_enabled
3030
bucket_notifications_type = var.bucket_notifications_type
3131
bucket_notifications_prefix = var.bucket_notifications_prefix
32+
object_lock_configuration = var.object_lock_configuration
3233

3334
context = module.this.context
3435
}

variables.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,14 @@ variable "bucket_notifications_prefix" {
147147
type = string
148148
description = "Prefix filter. Used to manage object notifications"
149149
default = ""
150+
}
151+
152+
variable "object_lock_configuration" {
153+
type = object({
154+
mode = string # Valid values are GOVERNANCE and COMPLIANCE.
155+
days = number
156+
years = number
157+
})
158+
default = null
159+
description = "A configuration for S3 object locking. With S3 Object Lock, you can store objects using a write-once-read-many (WORM) model. Object Lock can help prevent objects from being deleted or overwritten for a fixed amount of time or indefinitely."
150160
}

0 commit comments

Comments
 (0)