Skip to content

Commit

Permalink
Configuring IAM role for frile transfer S3 Bucket
Browse files Browse the repository at this point in the history
For use with RSD Admin Bastion instance profile
  • Loading branch information
Stephen James committed Nov 15, 2023
1 parent 60139a1 commit a53825c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
4 changes: 4 additions & 0 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ locals {
development_kinesis_destination_arn = nonsensitive(data.aws_secretsmanager_secret_version.development_kinesis_destination_arn.secret_string)

production_account_id = nonsensitive(data.aws_secretsmanager_secret_version.production_account_id.secret_string)

development_account_id = substr(local.dev_assume_role_arn, 13, 12)
pre-production_account_id = substr(local.pre_production_assume_role_arn, 13, 12)
# production_account_id = substr(local.production_assume_role_arn, 13, 12)
}
17 changes: 8 additions & 9 deletions modules/s3-assume-role/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ resource "aws_iam_role" "this" {
{
"Effect": "Allow",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"AWS": [
"arn:aws:iam::068084030754:root",
"arn:aws:iam::473630360727:root",
"arn:aws:iam::037161842252:root"
]
},
"Action": "sts:AssumeRole"
}
]
Expand All @@ -27,18 +31,13 @@ resource "aws_iam_role_policy" "this" {
}

data "aws_iam_policy_document" "this" {
statement {
actions = ["sts:AssumeRole"]
resources = [var.account_role_arns]
}

statement {
actions = [
"s3:*"
]
resources = [
"var.s3_bucket_arn/*",
"var.s3_bucket_arn"
"${var.s3_bucket_arn}/*",
"${var.s3_bucket_arn}"
]
}
}
Expand Down
6 changes: 3 additions & 3 deletions modules/s3-assume-role/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ variable "prefix_name" {
type = string
}

variable "account_role_arns" {
type = list(string)
}
#variable "account_ids" {
# type = list(string)
#}

variable "s3_bucket_arn" {
type = string
Expand Down
8 changes: 4 additions & 4 deletions mojo_file_transfer.tf
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ resource "aws_s3_bucket_server_side_encryption_configuration" "mojo_file_transfe
module "s3-mojo_file_transfer_assume_role" {
source = "./modules/s3-assume-role"

prefix_name = "s3-mojo-file-transfer"
account_role_arns = [local.dev_assume_role_arn, local.pre_production_assume_role_arn, local.production_assume_role_arn]
s3_bucket_arn = [aws_s3_bucket.mojo_file_transfer.arn]
prefix_name = "s3-mojo-file-transfer"
# account_ids = [ local.development_account_id, local.production_account_id, local.production_account_id ]
s3_bucket_arn = aws_s3_bucket.mojo_file_transfer.arn
tags = merge(module.label_staff.tags, {
Name = "mojo-file-transfer"
})
}
}

0 comments on commit a53825c

Please sign in to comment.