Skip to content

Commit

Permalink
fix: DBTP-1040 - filter_prefix terraform variable is optional (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksugden authored Jul 3, 2024
1 parent 73aa377 commit d0c5a00
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ my-s3-bucket:
days: 10 # Integer value. Alternatively years may be specified.
versioning: true # Optional
lifecycle_rules: # Optional. If present, contains a list of rules.
- filter_prefix: "bananas/" # Optional
- filter_prefix: "bananas/" # Optional. If none, the rule applies to all objects. Use an empty string for a catch-all rule.
expiration_days: 10 # Integer value
enabled: true # Mandatory flag
objects: # Optional. If present, contains a list of objects
Expand Down
31 changes: 30 additions & 1 deletion s3/tests/unit.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,42 @@ run "aws_s3_bucket_lifecycle_configuration_unit_test" {

assert {
condition = aws_s3_bucket_lifecycle_configuration.lifecycle-configuration[0].rule[0].expiration[0].days == 90
error_message = "Should be: /foo"
error_message = "Should be: 90"
}

assert {
condition = aws_s3_bucket_lifecycle_configuration.lifecycle-configuration[0].rule[0].abort_incomplete_multipart_upload[0].days_after_initiation == 7
error_message = "Should be: 7"
}

assert {
condition = aws_s3_bucket_lifecycle_configuration.lifecycle-configuration[0].rule[0].status == "Enabled"
error_message = "Should be: Enabled"
}
}

run "aws_s3_bucket_lifecycle_configuration_no_prefix_unit_test" {
command = plan

variables {
config = {
"bucket_name" = "dbt-terraform-test-s3-module",
"type" = "string",
"lifecycle_rules" = [{ "expiration_days" = 90, "enabled" = true }],
"objects" = [],
}
}

### Test aws_s3_bucket_lifecycle_configuration resource when no prefix is used ###
assert {
condition = aws_s3_bucket_lifecycle_configuration.lifecycle-configuration[0].rule[0].filter[0] != null
error_message = "Should be: {}"
}

assert {
condition = aws_s3_bucket_lifecycle_configuration.lifecycle-configuration[0].rule[0].filter[0].prefix == null
error_message = "Should be: null"
}
}

run "aws_s3_bucket_object_lock_configuration_governance_unit_test" {
Expand Down
2 changes: 1 addition & 1 deletion s3/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ variable "config" {
years = optional(number)
}))
lifecycle_rules = optional(list(object({
filter_prefix = string
filter_prefix = optional(string)
expiration_days = number
enabled = bool
})
Expand Down

0 comments on commit d0c5a00

Please sign in to comment.