Sets up bi-directional replication between two AWS S3 buckets located in different regions.

Terraform Template

resource "aws_s3_bucket" "east" {
  bucket = "tf-test-bucket-east-12345"
}

resource "aws_s3_bucket" "west" {
  bucket = "tf-test-bucket-west-12345"
  provider = "aws.west"
}

resource "aws_s3_bucket_replication_configuration" "east_to_west" {
  bucket = aws_s3_bucket.east.id
  depends_on = ["aws_s3_bucket_versioning.east"]
  role = "aws_iam_role.east_replication.arn"

  rule {

    destination {
      bucket = aws_s3_bucket.west.arn
      storage_class = "STANDARD"
    }

    filter {
      prefix = "foo"
    }
    id = "foobar"
    status = "Enabled"
  }
}

resource "aws_s3_bucket_replication_configuration" "west_to_east" {
  bucket = aws_s3_bucket.west.id
  depends_on = ["aws_s3_bucket_versioning.west"]
  provider = "aws.west"
  role = "aws_iam_role.west_replication.arn"

  rule {

    destination {
      bucket = aws_s3_bucket.east.arn
      storage_class = "STANDARD"
    }

    filter {
      prefix = "foo"
    }
    id = "foobar"
    status = "Enabled"
  }
}

resource "aws_s3_bucket_versioning" "east" {
  bucket = aws_s3_bucket.east.id

  versioning_configuration {
    status = "Enabled"
  }
}

resource "aws_s3_bucket_versioning" "west" {
  bucket = aws_s3_bucket.west.id
  provider = "aws.west"

  versioning_configuration {
    status = "Enabled"
  }
}