Skip to content

Instantly share code, notes, and snippets.

@100daysofdevops
Created March 26, 2019 22:14
Show Gist options
  • Select an option

  • Save 100daysofdevops/c9480a5a094ab7cd3db0d9703b1972e2 to your computer and use it in GitHub Desktop.

Select an option

Save 100daysofdevops/c9480a5a094ab7cd3db0d9703b1972e2 to your computer and use it in GitHub Desktop.
provider "aws" {
region = "us-west-2"
}
provider "aws" {
alias = "east"
region = "us-east-1"
}
resource "aws_iam_role" "my-replication-role" {
name = "my-replication-role"
assume_role_policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "s3.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
POLICY
}
resource "aws_iam_policy" "my-replication-policy" {
name = "my-replication-policy"
policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"s3:GetReplicationConfiguration",
"s3:ListBucket"
],
"Effect": "Allow",
"Resource": [
"${aws_s3_bucket.bucket.arn}"
]
},
{
"Action": [
"s3:GetObjectVersion",
"s3:GetObjectVersionAcl"
],
"Effect": "Allow",
"Resource": [
"${aws_s3_bucket.bucket.arn}/*"
]
},
{
"Action": [
"s3:ReplicateObject",
"s3:ReplicateDelete"
],
"Effect": "Allow",
"Resource": "${aws_s3_bucket.destination.arn}/*"
}
]
}
POLICY
}
resource "aws_iam_policy_attachment" "replication" {
name = "tf-iam-role-attachment-replication-12345"
roles = ["${aws_iam_role.my-replication-role.name}"]
policy_arn = "${aws_iam_policy.my-replication-policy.arn}"
}
resource "aws_s3_bucket" "destination" {
bucket = "my-destination-s3-bucket-to-test-crr1"
region = "us-west-2"
versioning {
enabled = true
}
}
resource "aws_s3_bucket" "bucket" {
provider = "aws.east"
bucket = "my-source-s3-bucket-to-test-crr1"
acl = ""
region = "us-east-1"
versioning {
enabled = true
}
replication_configuration {
role = "${aws_iam_role.my-replication-role.arn}"
rules {
prefix = ""
status = "Enabled"
destination {
bucket = "${aws_s3_bucket.destination.arn}"
storage_class = "STANDARD"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment