Skip to content

Commit

Permalink
Merge pull request #2 from sam-h-bean/mrbean/change-provider
Browse files Browse the repository at this point in the history
Mrbean/change provider
  • Loading branch information
sam-h-bean authored Jan 20, 2021
2 parents f0fcfcb + 51bc983 commit ce9b4eb
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ Terraform Module for managing s3 bucket cross-account cross-region replication.

- Terraform 0.11 module provider inheritance block:

- `aws.source` - AWS provider alias for source account
- `aws.dest` - AWS provider alias for destination account
- `aws.source_of_replication` - AWS provider alias for source account
- `aws.destination_of_replication` - AWS provider alias for destination account

#### Optional

Expand Down Expand Up @@ -47,8 +47,8 @@ module "s3-cross-account-replication" {
replication_name = "my-replication-name"
providers {
"aws.source" = "aws.source"
"aws.dest" = "aws.dest"
"aws.source_of_replication" = "source_of_replication"
"aws.destination_of_replication" = "aws.destination_of_replication"
}
}
Expand Down Expand Up @@ -81,7 +81,11 @@ Authors
Changelog
=========

1.0.0 - Initial release.
1.0.0 - Initial release

2.0.0 - TF 0.12.X

3.0.0 - Rename povider

License
=======
Expand Down
8 changes: 4 additions & 4 deletions iam-source.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,25 @@ data "aws_iam_policy_document" "source_write" {
}

resource "aws_iam_policy" "source_write" {
provider = aws.source
provider = aws.source_of_replication
name_prefix = "${local.replication_name}-source-write-"
policy = data.aws_iam_policy_document.source_write.json
}

resource "aws_iam_user" "source_write" {
provider = aws.source
provider = aws.source_of_replication
name = "${local.replication_name}-source-write-user"
force_destroy = true
}

resource "aws_iam_user_policy_attachment" "source_write" {
provider = aws.source
provider = aws.source_of_replication
user = aws_iam_user.source_write.name
policy_arn = aws_iam_policy.source_write.arn
}

resource "aws_iam_access_key" "source_write" {
provider = aws.source
provider = aws.source_of_replication
user = aws_iam_user.source_write.name
}

8 changes: 4 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# MAIN

provider "aws" {
alias = "source"
alias = "source_of_replication"
}

provider "aws" {
alias = "dest"
alias = "destination_of_replication"
}

data "aws_caller_identity" "source" {
provider = aws.source
provider = aws.source_of_replication
}

data "aws_caller_identity" "dest" {
provider = aws.dest
provider = aws.destination_of_replication
}

2 changes: 1 addition & 1 deletion s3-dest.tf
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ data "aws_iam_policy_document" "dest_bucket_policy" {

resource "aws_s3_bucket" "dest" {
count = var.create_dest_bucket == "true" ? 1 : 0
provider = aws.dest
provider = aws.destination_of_replication
bucket = var.dest_bucket_name
region = var.dest_region
policy = data.aws_iam_policy_document.dest_bucket_policy.json
Expand Down
8 changes: 4 additions & 4 deletions s3-source.tf
Original file line number Diff line number Diff line change
Expand Up @@ -74,27 +74,27 @@ data "aws_iam_policy_document" "source_replication_policy" {
}

resource "aws_iam_role" "source_replication" {
provider = aws.source
provider = aws.source_of_replication
name = "${local.replication_name}-replication-role"
assume_role_policy = data.aws_iam_policy_document.source_replication_role.json
}

resource "aws_iam_policy" "source_replication" {
provider = aws.source
provider = aws.source_of_replication
name = "${local.replication_name}-replication-policy"
policy = data.aws_iam_policy_document.source_replication_policy.json
}

resource "aws_iam_role_policy_attachment" "source_replication" {
provider = aws.source
provider = aws.source_of_replication
role = aws_iam_role.source_replication.name
policy_arn = aws_iam_policy.source_replication.arn
}

# S3 source bucket

resource "aws_s3_bucket" "source" {
provider = aws.source
provider = aws.source_of_replication
bucket = var.source_bucket_name
region = var.source_region

Expand Down

0 comments on commit ce9b4eb

Please sign in to comment.