├── cross-account ├── versions.tf ├── outputs.tf ├── terraform.tfvars.template ├── provider.tf ├── variables.tf ├── sample.txt ├── destination.tf └── source.tf ├── same-account ├── versions.tf ├── terraform.tfvars.template ├── outputs.tf ├── provider.tf ├── variables.tf ├── destination.tf ├── sample.txt └── source.tf ├── .gitignore ├── README.md └── LICENSE /cross-account/versions.tf: -------------------------------------------------------------------------------- 1 | 2 | terraform { 3 | required_version = ">= 0.12" 4 | } 5 | -------------------------------------------------------------------------------- /same-account/versions.tf: -------------------------------------------------------------------------------- 1 | 2 | terraform { 3 | required_version = ">= 0.12" 4 | } 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.tfstate 2 | *.tfstate.backup 3 | *.tfstate.*.backup 4 | .terraform/ 5 | .DS_Store 6 | terraform.tfvars 7 | -------------------------------------------------------------------------------- /same-account/terraform.tfvars.template: -------------------------------------------------------------------------------- 1 | aws_region=eu-west-2 2 | aws_profile=??? 3 | source_region=??? 4 | dest_region=??? 5 | -------------------------------------------------------------------------------- /cross-account/outputs.tf: -------------------------------------------------------------------------------- 1 | output "destination_bucket" { 2 | value = aws_s3_bucket.destination.arn 3 | } 4 | 5 | output "source_bucket" { 6 | value = aws_s3_bucket.source.arn 7 | } 8 | 9 | -------------------------------------------------------------------------------- /same-account/outputs.tf: -------------------------------------------------------------------------------- 1 | output "destination_bucket" { 2 | value = aws_s3_bucket.destination.arn 3 | } 4 | 5 | output "source_bucket" { 6 | value = aws_s3_bucket.source.arn 7 | } 8 | 9 | -------------------------------------------------------------------------------- /cross-account/terraform.tfvars.template: -------------------------------------------------------------------------------- 1 | source_region = "eu-west-2" 2 | source_profile = "???" 3 | source_account = "" 4 | dest_region = "eu-west-1" 5 | dest_profile = "???" 6 | dest_account = "" 7 | -------------------------------------------------------------------------------- /same-account/provider.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = var.aws_region 3 | profile = var.aws_profile 4 | } 5 | 6 | provider "aws" { 7 | alias = "source" 8 | region = var.source_region 9 | profile = var.aws_profile 10 | } 11 | 12 | provider "aws" { 13 | alias = "dest" 14 | region = var.dest_region 15 | profile = var.aws_profile 16 | } 17 | 18 | -------------------------------------------------------------------------------- /cross-account/provider.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = var.source_region 3 | profile = var.source_profile 4 | } 5 | 6 | provider "aws" { 7 | alias = "source" 8 | region = var.source_region 9 | profile = var.source_profile 10 | } 11 | 12 | provider "aws" { 13 | alias = "dest" 14 | region = var.dest_region 15 | profile = var.dest_profile 16 | } 17 | 18 | -------------------------------------------------------------------------------- /same-account/variables.tf: -------------------------------------------------------------------------------- 1 | variable "tags" { 2 | default = { 3 | "owner" = "rahook" 4 | "project" = "s3-replication" 5 | "client" = "Internal" 6 | } 7 | } 8 | 9 | variable "source_region" { 10 | default = "eu-west-2" 11 | } 12 | 13 | variable "dest_region" { 14 | default = "eu-west-1" 15 | } 16 | 17 | variable "bucket_prefix" { 18 | default = "crr-example" 19 | } 20 | 21 | variable "aws_region" { 22 | } 23 | 24 | variable "aws_profile" { 25 | } 26 | 27 | -------------------------------------------------------------------------------- /cross-account/variables.tf: -------------------------------------------------------------------------------- 1 | variable "tags" { 2 | default = { 3 | "owner" = "rahook" 4 | "project" = "s3-replication" 5 | "client" = "Internal" 6 | } 7 | } 8 | 9 | variable "bucket_prefix" { 10 | default = "crr-example" 11 | } 12 | 13 | variable "source_account" { 14 | description = "ID of the source account" 15 | } 16 | 17 | variable "source_region" { 18 | default = "eu-west-2" 19 | } 20 | 21 | variable "source_profile" { 22 | description = "name of the source profile being used" 23 | } 24 | 25 | variable "dest_account" { 26 | description = "ID of the destination account" 27 | } 28 | 29 | variable "dest_region" { 30 | default = "eu-west-1" 31 | } 32 | 33 | variable "dest_profile" { 34 | description = "name of the destination profile being used" 35 | } 36 | 37 | -------------------------------------------------------------------------------- /same-account/destination.tf: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------------ 2 | # KMS key for server side encryption on the destination bucket 3 | # ------------------------------------------------------------------------------ 4 | resource "aws_kms_key" "destination" { 5 | provider = aws.dest 6 | deletion_window_in_days = 7 7 | 8 | tags = merge( 9 | { 10 | "Name" = "destination_data" 11 | }, 12 | var.tags, 13 | ) 14 | } 15 | 16 | resource "aws_kms_alias" "destination" { 17 | provider = aws.dest 18 | name = "alias/destination" 19 | target_key_id = aws_kms_key.destination.key_id 20 | } 21 | 22 | # ------------------------------------------------------------------------------ 23 | # S3 bucket to act as the replication target. 24 | # ------------------------------------------------------------------------------ 25 | resource "aws_s3_bucket" "destination" { 26 | provider = aws.dest 27 | bucket_prefix = var.bucket_prefix 28 | acl = "private" 29 | region = var.dest_region 30 | 31 | versioning { 32 | enabled = true 33 | } 34 | 35 | lifecycle { 36 | prevent_destroy = false 37 | } 38 | 39 | server_side_encryption_configuration { 40 | rule { 41 | apply_server_side_encryption_by_default { 42 | kms_master_key_id = aws_kms_key.destination.arn 43 | sse_algorithm = "aws:kms" 44 | } 45 | } 46 | } 47 | 48 | tags = merge( 49 | { 50 | "Name" = "Destination Bucket" 51 | }, 52 | var.tags, 53 | ) 54 | } 55 | 56 | -------------------------------------------------------------------------------- /same-account/sample.txt: -------------------------------------------------------------------------------- 1 | CHAPTER 1. Loomings. 2 | 3 | Call me Ishmael. Some years ago—never mind how long precisely—having 4 | little or no money in my purse, and nothing particular to interest me 5 | on shore, I thought I would sail about a little and see the watery part 6 | of the world. It is a way I have of driving off the spleen and 7 | regulating the circulation. Whenever I find myself growing grim about 8 | the mouth; whenever it is a damp, drizzly November in my soul; whenever 9 | I find myself involuntarily pausing before coffin warehouses, and 10 | bringing up the rear of every funeral I meet; and especially whenever 11 | my hypos get such an upper hand of me, that it requires a strong moral 12 | principle to prevent me from deliberately stepping into the street, and 13 | methodically knocking people’s hats off—then, I account it high time to 14 | get to sea as soon as I can. This is my substitute for pistol and ball. 15 | With a philosophical flourish Cato throws himself upon his sword; I 16 | quietly take to the ship. There is nothing surprising in this. If they 17 | but knew it, almost all men in their degree, some time or other, 18 | cherish very nearly the same feelings towards the ocean with me. 19 | 20 | There now is your insular city of the Manhattoes, belted round by 21 | wharves as Indian isles by coral reefs—commerce surrounds it with her 22 | surf. Right and left, the streets take you waterward. Its extreme 23 | downtown is the battery, where that noble mole is washed by waves, and 24 | cooled by breezes, which a few hours previous were out of sight of 25 | land. Look at the crowds of water-gazers there. 26 | 27 | Circumambulate the city of a dreamy Sabbath afternoon. Go from Corlears 28 | Hook to Coenties Slip, and from thence, by Whitehall, northward. What 29 | do you see?—Posted like silent sentinels all around the town, stand 30 | thousands upon thousands of mortal men fixed in ocean reveries. Some 31 | leaning against the spiles; some seated upon the pier-heads; some 32 | looking over the bulwarks of ships from China; some high aloft in the 33 | rigging, as if striving to get a still better seaward peep. But these 34 | are all landsmen; of week days pent up in lath and plaster—tied to 35 | counters, nailed to benches, clinched to desks. How then is this? Are 36 | the green fields gone? What do they here? 37 | 38 | But look! here come more crowds, pacing straight for the water, and 39 | seemingly bound for a dive. Strange! Nothing will content them but the 40 | extremest limit of the land; loitering under the shady lee of yonder 41 | warehouses will not suffice. No. They must get just as nigh the water 42 | as they possibly can without falling in. And there they stand—miles of 43 | them—leagues. Inlanders all, they come from lanes and alleys, streets 44 | and avenues—north, east, south, and west. Yet here they all unite. Tell 45 | me, does the magnetic virtue of the needles of the compasses of all 46 | those ships attract them thither? 47 | 48 | -------------------------------------------------------------------------------- /cross-account/sample.txt: -------------------------------------------------------------------------------- 1 | CHAPTER 1. Loomings. 2 | 3 | Call me Ishmael. Some years ago—never mind how long precisely—having 4 | little or no money in my purse, and nothing particular to interest me 5 | on shore, I thought I would sail about a little and see the watery part 6 | of the world. It is a way I have of driving off the spleen and 7 | regulating the circulation. Whenever I find myself growing grim about 8 | the mouth; whenever it is a damp, drizzly November in my soul; whenever 9 | I find myself involuntarily pausing before coffin warehouses, and 10 | bringing up the rear of every funeral I meet; and especially whenever 11 | my hypos get such an upper hand of me, that it requires a strong moral 12 | principle to prevent me from deliberately stepping into the street, and 13 | methodically knocking people’s hats off—then, I account it high time to 14 | get to sea as soon as I can. This is my substitute for pistol and ball. 15 | With a philosophical flourish Cato throws himself upon his sword; I 16 | quietly take to the ship. There is nothing surprising in this. If they 17 | but knew it, almost all men in their degree, some time or other, 18 | cherish very nearly the same feelings towards the ocean with me. 19 | 20 | There now is your insular city of the Manhattoes, belted round by 21 | wharves as Indian isles by coral reefs—commerce surrounds it with her 22 | surf. Right and left, the streets take you waterward. Its extreme 23 | downtown is the battery, where that noble mole is washed by waves, and 24 | cooled by breezes, which a few hours previous were out of sight of 25 | land. Look at the crowds of water-gazers there. 26 | 27 | Circumambulate the city of a dreamy Sabbath afternoon. Go from Corlears 28 | Hook to Coenties Slip, and from thence, by Whitehall, northward. What 29 | do you see?—Posted like silent sentinels all around the town, stand 30 | thousands upon thousands of mortal men fixed in ocean reveries. Some 31 | leaning against the spiles; some seated upon the pier-heads; some 32 | looking over the bulwarks of ships from China; some high aloft in the 33 | rigging, as if striving to get a still better seaward peep. But these 34 | are all landsmen; of week days pent up in lath and plaster—tied to 35 | counters, nailed to benches, clinched to desks. How then is this? Are 36 | the green fields gone? What do they here? 37 | 38 | But look! here come more crowds, pacing straight for the water, and 39 | seemingly bound for a dive. Strange! Nothing will content them but the 40 | extremest limit of the land; loitering under the shady lee of yonder 41 | warehouses will not suffice. No. They must get just as nigh the water 42 | as they possibly can without falling in. And there they stand—miles of 43 | them—leagues. Inlanders all, they come from lanes and alleys, streets 44 | and avenues—north, east, south, and west. Yet here they all unite. Tell 45 | me, does the magnetic virtue of the needles of the compasses of all 46 | those ships attract them thither? 47 | 48 | -------------------------------------------------------------------------------- /cross-account/destination.tf: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------------ 2 | # KMS key for server side encryption on the destination bucket 3 | # ------------------------------------------------------------------------------ 4 | resource "aws_kms_key" "destination" { 5 | provider = aws.dest 6 | deletion_window_in_days = 7 7 | 8 | tags = merge( 9 | { 10 | "Name" = "destination_data" 11 | }, 12 | var.tags, 13 | ) 14 | 15 | policy = <