Skip to content

Commit 43e845e

Browse files
authored
fix: Always send filter map in replication config (terraform-aws-modules#105)
1 parent 29de41c commit 43e845e

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

examples/s3-replication/main.tf

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ module "s3_bucket" {
5858

5959
rules = [
6060
{
61-
id = "foo"
61+
id = "something-with-kms-and-filter"
6262
status = "Enabled"
6363
priority = 10
6464

@@ -86,25 +86,45 @@ module "s3_bucket" {
8686
}
8787
},
8888
{
89-
id = "bar"
89+
id = "something-with-filter"
9090
status = "Enabled"
9191
priority = 20
9292

93+
filter = {
94+
prefix = "two"
95+
tags = {
96+
ReplicateMe = "Yes"
97+
}
98+
}
99+
93100
destination = {
94101
bucket = "arn:aws:s3:::${local.destination_bucket_name}"
95102
storage_class = "STANDARD"
96103
}
97-
104+
},
105+
{
106+
id = "everything-with-filter"
107+
status = "Enabled"
108+
priority = 30
98109

99110
filter = {
100-
prefix = "two"
101-
tags = {
102-
ReplicateMe = "Yes"
103-
}
111+
prefix = ""
104112
}
105113

114+
destination = {
115+
bucket = "arn:aws:s3:::${local.destination_bucket_name}"
116+
storage_class = "STANDARD"
117+
}
106118
},
119+
{
120+
id = "everything-without-filters"
121+
status = "Enabled"
107122

123+
destination = {
124+
bucket = "arn:aws:s3:::${local.destination_bucket_name}"
125+
storage_class = "STANDARD"
126+
}
127+
},
108128
]
109129
}
110130

main.tf

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,16 @@ resource "aws_s3_bucket" "this" {
172172
}
173173
}
174174

175+
# Send empty map if `filter` is an empty map or absent entirely
175176
dynamic "filter" {
176-
for_each = length(keys(lookup(rules.value, "filter", {}))) == 0 ? [] : [lookup(rules.value, "filter", {})]
177+
for_each = length(keys(lookup(rules.value, "filter", {}))) == 0 ? [{}] : []
178+
179+
content {}
180+
}
181+
182+
# Send `filter` if it is present and has at least one field
183+
dynamic "filter" {
184+
for_each = length(keys(lookup(rules.value, "filter", {}))) != 0 ? [lookup(rules.value, "filter", {})] : []
177185

178186
content {
179187
prefix = lookup(filter.value, "prefix", null)

0 commit comments

Comments
 (0)