Skip to content

Commit

Permalink
added lifecycle variable type and structure (#55)
Browse files Browse the repository at this point in the history
* added lifecycle variable type and structure

* Continuous Integration - terraform fmt and terraform-docs

* Made all lifecycle_rules optional

* Continuous Integration - terraform fmt and terraform-docs

* added transition as optional list

* Continuous Integration - terraform fmt and terraform-docs

* correcting optional null value for transition

* Continuous Integration - terraform fmt and terraform-docs

* updated readme examples

---------

Co-authored-by: zachreborn <zachreborn@users.noreply.github.com>
  • Loading branch information
zachreborn and zachreborn committed Mar 28, 2024
1 parent 746212d commit 2213577
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 8 deletions.
4 changes: 2 additions & 2 deletions modules/aws/s3/bucket/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ module "logging_bucket" {
```

### Lifecycle Rules With All Available Options
This example shows all of the available options. All transition configurations are lists and can have multiple transitions configured.
This example shows all of the available options. All transition configurations are lists and can have multiple transitions configured. Any combination of the options can be used to create the desired lifecycle rule.
```
module "logging_bucket" {
source = "github.com/zachreborn/terraform-modules//modules/aws/s3/bucket"
Expand Down Expand Up @@ -381,7 +381,7 @@ No modules.
| <a name="input_key_name_prefix"></a> [key\_name\_prefix](#input\_key\_name\_prefix) | (Optional) Creates an unique alias beginning with the specified prefix. The name must start with the word alias followed by a forward slash (alias/). | `string` | `"alias/s3_key_"` | no |
| <a name="input_key_policy"></a> [key\_policy](#input\_key\_policy) | (Optional) A valid policy JSON document. Although this is a key policy, not an IAM policy, an aws\_iam\_policy\_document, in the form that designates a principal, can be used. For more information about building policy documents with Terraform, see the AWS IAM Policy Document Guide. | `string` | `""` | no |
| <a name="input_key_usage"></a> [key\_usage](#input\_key\_usage) | (Optional) Specifies the intended use of the key. Defaults to ENCRYPT\_DECRYPT, and only symmetric encryption and decryption are supported. | `string` | `"ENCRYPT_DECRYPT"` | no |
| <a name="input_lifecycle_rules"></a> [lifecycle\_rules](#input\_lifecycle\_rules) | (Optional) Configuration of object lifecycle management (LCM). Can have several rules as a list of maps where each map is the lifecycle rule configuration. Type should be list(map(string)). | `any` | `null` | no |
| <a name="input_lifecycle_rules"></a> [lifecycle\_rules](#input\_lifecycle\_rules) | (Optional) Configuration of object lifecycle management (LCM). Can have several rules as a list of maps where each map is the lifecycle rule configuration. | <pre>list(object({<br> id = string<br> status = string<br> abort_incomplete_multipart_upload = optional(object({<br> days_after_initiation = number<br> }))<br> expiration = optional(object({<br> date = optional(string)<br> days = optional(number)<br> expired_object_delete_marker = optional(bool)<br> }))<br> filter = optional(object({<br> object_size_greater_than = optional(number)<br> object_size_less_than = optional(number)<br> prefix = optional(string)<br> tag = optional(map(string))<br> }))<br> noncurrent_version_expiration = optional(object({<br> newer_noncurrent_versions = optional(number)<br> noncurrent_days = optional(number)<br> }))<br> noncurrent_version_transitions = optional(list(object({<br> newer_noncurrent_versions = optional(number)<br> noncurrent_days = optional(number)<br> storage_class = optional(string)<br> })))<br> transition = optional(list(object({<br> date = optional(string)<br> days = optional(number)<br> storage_class = optional(string)<br> })), [])<br> }))</pre> | `null` | no |
| <a name="input_logging_target_bucket"></a> [logging\_target\_bucket](#input\_logging\_target\_bucket) | (Optional) The name of the bucket that will receive the logs. Required if logging of the S3 bucket is set to true. | `string` | `null` | no |
| <a name="input_logging_target_prefix"></a> [logging\_target\_prefix](#input\_logging\_target\_prefix) | (Optional) The prefix that is prepended to all log object keys. If not set, the logs are stored in the root of the bucket. | `string` | `"log/"` | no |
| <a name="input_mfa_delete"></a> [mfa\_delete](#input\_mfa\_delete) | (Optional) Specifies whether MFA delete is enabled in the bucket versioning configuration. Valid values: Enabled or Disabled. | `string` | `"Disabled"` | no |
Expand Down
37 changes: 34 additions & 3 deletions modules/aws/s3/bucket/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,40 @@ variable "intelligent_tiering_days" {
######################

variable "lifecycle_rules" {
type = any
description = "(Optional) Configuration of object lifecycle management (LCM). Can have several rules as a list of maps where each map is the lifecycle rule configuration. Type should be list(map(string))."
default = null
description = "(Optional) Configuration of object lifecycle management (LCM). Can have several rules as a list of maps where each map is the lifecycle rule configuration."
type = list(object({
id = string
status = string
abort_incomplete_multipart_upload = optional(object({
days_after_initiation = number
}))
expiration = optional(object({
date = optional(string)
days = optional(number)
expired_object_delete_marker = optional(bool)
}))
filter = optional(object({
object_size_greater_than = optional(number)
object_size_less_than = optional(number)
prefix = optional(string)
tag = optional(map(string))
}))
noncurrent_version_expiration = optional(object({
newer_noncurrent_versions = optional(number)
noncurrent_days = optional(number)
}))
noncurrent_version_transitions = optional(list(object({
newer_noncurrent_versions = optional(number)
noncurrent_days = optional(number)
storage_class = optional(string)
})))
transition = optional(list(object({
date = optional(string)
days = optional(number)
storage_class = optional(string)
})), [])
}))
default = null
}

######################
Expand Down
1 change: 1 addition & 0 deletions modules/aws/transfer_family/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ _For more examples, please refer to the [Documentation](https://github.com/zachr
| <a name="input_host_key"></a> [host\_key](#input\_host\_key) | (Optional) The RSA, ECDSA, or ED25519 private key. This must be created ahead of time. | `string` | `null` | no |
| <a name="input_identity_provider_type"></a> [identity\_provider\_type](#input\_identity\_provider\_type) | (Optional) The mode of authentication enabled for this service. Valid values are SERVICE\_MANAGED or API\_GATEWAY | `string` | `"SERVICE_MANAGED"` | no |
| <a name="input_invocation_role"></a> [invocation\_role](#input\_invocation\_role) | (Optional) The ARN of the IAM role that controls your authentication with an identity provider\_type through API\_GATEWAY. | `string` | `null` | no |
| <a name="input_lifecycle_rules"></a> [lifecycle\_rules](#input\_lifecycle\_rules) | (Optional) Configuration of object lifecycle management (LCM). Can have several rules as a list of maps where each map is the lifecycle rule configuration. | <pre>list(object({<br> id = string<br> status = string<br> abort_incomplete_multipart_upload = optional(object({<br> days_after_initiation = number<br> }))<br> expiration = optional(object({<br> date = optional(string)<br> days = optional(number)<br> expired_object_delete_marker = optional(bool)<br> }))<br> filter = optional(object({<br> object_size_greater_than = optional(number)<br> object_size_less_than = optional(number)<br> prefix = optional(string)<br> tag = optional(map(string))<br> }))<br> noncurrent_version_expiration = optional(object({<br> newer_noncurrent_versions = optional(number)<br> noncurrent_days = optional(number)<br> }))<br> noncurrent_version_transitions = optional(list(object({<br> newer_noncurrent_versions = optional(number)<br> noncurrent_days = optional(number)<br> storage_class = optional(string)<br> })))<br> transition = optional(list(object({<br> date = optional(string)<br> days = optional(number)<br> storage_class = optional(string)<br> })), [])<br> }))</pre> | `null` | no |
| <a name="input_logging_role"></a> [logging\_role](#input\_logging\_role) | (Optional) The ARN of the IAM role that allows the service to write your server access logs to a Amazon CloudWatch log group. | `string` | `null` | no |
| <a name="input_name"></a> [name](#input\_name) | (Required) The name of the AWS Transfer Family server used to name the resources created. | `string` | n/a | yes |
| <a name="input_passive_ip"></a> [passive\_ip](#input\_passive\_ip) | (Optional) Sets passive mode for FTP and FTPS protocols and the associated IPv4 address to associate. | `string` | `null` | no |
Expand Down
5 changes: 3 additions & 2 deletions modules/aws/transfer_family/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ resource "aws_transfer_server" "this" {
module "bucket" {
source = "../s3/bucket"

bucket_prefix = var.name
tags = var.tags
bucket_prefix = var.name
lifecycle_rules = var.lifecycle_rules
tags = var.tags
}

##############
Expand Down
37 changes: 36 additions & 1 deletion modules/aws/transfer_family/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,42 @@ variable "vpc_id" {
# S3 Bucket Variables
###########################

variable "lifecycle_rules" {
description = "(Optional) Configuration of object lifecycle management (LCM). Can have several rules as a list of maps where each map is the lifecycle rule configuration."
type = list(object({
id = string
status = string
abort_incomplete_multipart_upload = optional(object({
days_after_initiation = number
}))
expiration = optional(object({
date = optional(string)
days = optional(number)
expired_object_delete_marker = optional(bool)
}))
filter = optional(object({
object_size_greater_than = optional(number)
object_size_less_than = optional(number)
prefix = optional(string)
tag = optional(map(string))
}))
noncurrent_version_expiration = optional(object({
newer_noncurrent_versions = optional(number)
noncurrent_days = optional(number)
}))
noncurrent_version_transitions = optional(list(object({
newer_noncurrent_versions = optional(number)
noncurrent_days = optional(number)
storage_class = optional(string)
})))
transition = optional(list(object({
date = optional(string)
days = optional(number)
storage_class = optional(string)
})), [])
}))
default = null
}

###########################
# User Variables
Expand All @@ -193,7 +229,6 @@ variable "users" {
default = {}
}


###########################
# General Variables
###########################
Expand Down

0 comments on commit 2213577

Please sign in to comment.