Skip to content

Commit

Permalink
Merge pull request #24 from dasmeta/DMVP-5796
Browse files Browse the repository at this point in the history
feat: intelligent lifecycle policy support
  • Loading branch information
sophie-dasmeta-com authored Oct 23, 2024
2 parents 254cf5d + 4470530 commit c3ccea4
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ module "my_bucket" {

| Name | Type |
|------|------|
| [aws_s3_bucket_intelligent_tiering_configuration.bucket_intelligent_tiering](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_intelligent_tiering_configuration) | resource |
| [aws_s3_bucket_notification.bucket_notification](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_notification) | resource |
| [aws_s3_object.index](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_object) | resource |
| [aws_sqs_queue.queue](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sqs_queue) | resource |
Expand All @@ -112,6 +113,7 @@ module "my_bucket" {
| <a name="input_block_public_policy"></a> [block\_public\_policy](#input\_block\_public\_policy) | Whether Amazon S3 should block public bucket policies for this bucket. | `bool` | `false` | no |
| <a name="input_bucket_files"></a> [bucket\_files](#input\_bucket\_files) | Initial content for bucket, use acl and pattern params if you need more control. | <pre>object({<br/> path = string<br/> })</pre> | <pre>{<br/> "path": ""<br/>}</pre> | no |
| <a name="input_bucket_iam_policy"></a> [bucket\_iam\_policy](#input\_bucket\_iam\_policy) | AWS bucket policy | <pre>list(object({<br/> effect = optional(string, "Allow") # Effect of the policy (Allow or Deny)<br/> actions = list(string) # Actions like sts:AssumeRole<br/> principals = any # Principals (e.g., AWS, Service, Federated)<br/> conditions = optional(any, []) # Optional conditions for assume role<br/> }))</pre> | `[]` | no |
| <a name="input_bucket_intelligent_tiering"></a> [bucket\_intelligent\_tiering](#input\_bucket\_intelligent\_tiering) | Intelligent lifecycle policy | <pre>list(object({<br/> tier = string<br/> days = number<br/> }))</pre> | `[]` | no |
| <a name="input_control_object_ownership"></a> [control\_object\_ownership](#input\_control\_object\_ownership) | Manage S3 Bucket Ownership Controls on this bucket or not. | `bool` | `false` | no |
| <a name="input_cors_rule"></a> [cors\_rule](#input\_cors\_rule) | List of maps containing rules for Cross-Origin Resource Sharing. | `any` | `[]` | no |
| <a name="input_create_iam_user"></a> [create\_iam\_user](#input\_create\_iam\_user) | Whether to create specific api access user to this created bucket. | `bool` | `false` | no |
Expand Down
15 changes: 15 additions & 0 deletions lifecycle-policy.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
resource "aws_s3_bucket_intelligent_tiering_configuration" "bucket_intelligent_tiering" {
count = length(var.bucket_intelligent_tiering) > 0 ? 1 : 0

bucket = module.bucket.s3_bucket_id
name = "${module.bucket.s3_bucket_id}-intelligent-lifecycle"

dynamic "tiering" {
for_each = var.bucket_intelligent_tiering
content {
access_tier = tiering.value.tier
days = tiering.value.days
}
}

}
29 changes: 29 additions & 0 deletions tests/lifecycle-policy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# lifecycle-policy

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements

No requirements.

## Providers

No providers.

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_custom-policies"></a> [custom-policies](#module\_custom-policies) | ../.. | n/a |

## Resources

No resources.

## Inputs

No inputs.

## Outputs

No outputs.
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
16 changes: 16 additions & 0 deletions tests/lifecycle-policy/example.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

provider "aws" {
region = "eu-central-1"
}

module "custom-policies" {
source = "../.."

acl = "private"
name = "policies-bucket-example-wpas-2"

bucket_intelligent_tiering = [{
tier = "ARCHIVE_ACCESS"
days = 90
}]
}
9 changes: 9 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,12 @@ variable "bucket_iam_policy" {
description = "AWS bucket policy"
default = []
}

variable "bucket_intelligent_tiering" {
type = list(object({
tier = string
days = number
}))
default = []
description = "Intelligent lifecycle policy"
}

0 comments on commit c3ccea4

Please sign in to comment.