Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed s3-replication example
  • Loading branch information
antonbabenko committed Mar 30, 2022
commit 9b7b536325875b0e5a0256571a8bd7a363b95396
110 changes: 58 additions & 52 deletions examples/s3-replication/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,18 @@ module "s3_bucket" {

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

delete_marker_replication = false

source_selection_criteria = {
replica_modifications = {
status = "Enabled"
},
}
sse_kms_encrypted_objects = {
enabled = false #true
enabled = true
}
}

Expand All @@ -95,66 +95,72 @@ module "s3_bucket" {
}

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

replica_kms_key_id = aws_kms_key.replica.arn
account_id = data.aws_caller_identity.current.account_id

access_control_translation = {
owner = "Destination"
}

replication_time = {
status = "Enabled"
minutes = 15
}

metrics = {
status = "Enabled"
minutes = 15
}
}
},
# {
# 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 = ""
# }
#
# destination = {
# bucket = "arn:aws:s3:::${local.destination_bucket_name}"
# storage_class = "STANDARD"
# }
# },
# {
# id = "everything-without-filters"
# status = "Enabled"
#
# delete_marker_replication = true
# existing_object_replication = false
#
# destination = {
# bucket = "arn:aws:s3:::${local.destination_bucket_name}"
# storage_class = "STANDARD"
# }
# },
{
id = "something-with-filter"
priority = 20

delete_marker_replication = false

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

delete_marker_replication = true

filter = {
prefix = ""
}

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

delete_marker_replication = true

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

Expand Down
6 changes: 5 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ resource "aws_s3_bucket_replication_configuration" "this" {
id = try(rule.value.id, null)
priority = try(rule.value.priority, null)
prefix = try(rule.value.prefix, null)
status = rule.value.status
status = try(tobool(rule.value.status) ? "Enabled" : "Disabled", title(lower(rule.value.status)), "Enabled")

dynamic "delete_marker_replication" {
for_each = flatten(try([rule.value.delete_marker_replication_status], [rule.value.delete_marker_replication], []))
Expand All @@ -365,6 +365,10 @@ resource "aws_s3_bucket_replication_configuration" "this" {
}
}

# Amazon S3 does not support this argument according to:
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_replication_configuration
# More infor about what does Amazon S3 replicate?
# https://docs.aws.amazon.com/AmazonS3/latest/userguide/replication-what-is-isnot-replicated.html
dynamic "existing_object_replication" {
for_each = flatten(try([rule.value.existing_object_replication_status], [rule.value.existing_object_replication], []))

Expand Down