Skip to content

Commit

Permalink
fix: Always send filter map in replication config (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
antonbabenko authored Aug 13, 2021
1 parent 29de41c commit 43e845e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
34 changes: 27 additions & 7 deletions examples/s3-replication/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ module "s3_bucket" {

rules = [
{
id = "foo"
id = "something-with-kms-and-filter"
status = "Enabled"
priority = 10

Expand Down Expand Up @@ -86,25 +86,45 @@ module "s3_bucket" {
}
},
{
id = "bar"
id = "something-with-filter"
status = "Enabled"
priority = 20

filter = {
prefix = "two"
tags = {
ReplicateMe = "Yes"
}
}

destination = {
bucket = "arn:aws:s3:::${local.destination_bucket_name}"
storage_class = "STANDARD"
}

},
{
id = "everything-with-filter"
status = "Enabled"
priority = 30

filter = {
prefix = "two"
tags = {
ReplicateMe = "Yes"
}
prefix = ""
}

destination = {
bucket = "arn:aws:s3:::${local.destination_bucket_name}"
storage_class = "STANDARD"
}
},
{
id = "everything-without-filters"
status = "Enabled"

destination = {
bucket = "arn:aws:s3:::${local.destination_bucket_name}"
storage_class = "STANDARD"
}
},
]
}

Expand Down
10 changes: 9 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,16 @@ resource "aws_s3_bucket" "this" {
}
}

# Send empty map if `filter` is an empty map or absent entirely
dynamic "filter" {
for_each = length(keys(lookup(rules.value, "filter", {}))) == 0 ? [] : [lookup(rules.value, "filter", {})]
for_each = length(keys(lookup(rules.value, "filter", {}))) == 0 ? [{}] : []

content {}
}

# Send `filter` if it is present and has at least one field
dynamic "filter" {
for_each = length(keys(lookup(rules.value, "filter", {}))) != 0 ? [lookup(rules.value, "filter", {})] : []

content {
prefix = lookup(filter.value, "prefix", null)
Expand Down

0 comments on commit 43e845e

Please sign in to comment.