Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Satellite region]: add IAM permissions for supporting feature service running in satellite region #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions deployment/emr_roles.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,25 @@ resource "aws_iam_role_policy_attachment" "emr_cross_account_policy_attachment"
role = aws_iam_role.cross_account_role.name
}

# CROSS ACCOUNT SATELLITE SERVING
resource "aws_iam_policy" "emr_cross_account_satellite_region_policy" {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: rename this to emr_cross_account_satellite_region since this is aws_iam_policy already

count = var.create_emr_roles && var.satellite_region != null ? 1 : 0
name = "tecton-${var.deployment_name}-cross-account-satellite-region-policy-emr"
policy = templatefile("${path.module}/../templates/satellite_serving_dynamodb_policy.json", {
ACCOUNT_ID = var.account_id
DEPLOYMENT_NAME = var.deployment_name
REGION = var.region
EMR_MANAGER_ROLE = aws_iam_role.emr_master_role[0].name
SPARK_ROLE = aws_iam_role.emr_spark_role[0].name
})
tags = local.tags
}
resource "aws_iam_role_policy_attachment" "emr_cross_account_satellite_region_policy_attachment" {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here rename to emr_cross_account_satellite_region since it's already policy_attachment by resource

count = var.create_emr_roles && var.satellite_region != null ? 1 : 0
policy_arn = aws_iam_policy.emr_cross_account_satellite_region_policy[0].arn
role = aws_iam_role.cross_account_role.name
}

# SPARK ROLE
resource "aws_iam_role" "emr_spark_role" {
count = var.create_emr_roles ? 1 : 0
Expand Down
17 changes: 17 additions & 0 deletions deployment/roles.tf
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,20 @@ resource "aws_iam_role_policy_attachment" "common_spark_policy_attachment" {
policy_arn = aws_iam_policy.common_spark_policy.arn
role = local.spark_role_name
}

resource "aws_iam_policy" "satellite_region_policy" {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

count = var.satellite_region == null ? 0 : 1
name = "tecton-satellite-region-policy"
policy = templatefile("${path.module}/../templates/satellite_ca_policy.json", {
ACCOUNT_ID = var.account_id
DEPLOYMENT_NAME = var.deployment_name
REGION = var.region
SATELLITE_REGION = var.satellite_region
})
tags = local.tags
}
resource "aws_iam_role_policy_attachment" "satellite_region_policy_attachment" {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here

count = var.satellite_region == null ? 0 : 1
policy_arn = aws_iam_policy.satellite_region_policy[0].arn
role = local.spark_role_name
}
4 changes: 4 additions & 0 deletions deployment/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ variable "account_id" {
variable "region" {
type = string
}
variable "satellite_region" {
type = string
default = null
}
variable "cross_account_external_id" {
type = string
}
Expand Down
40 changes: 40 additions & 0 deletions templates/satellite_ca_policy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DynamoDB",
"Effect": "Allow",
"Action": [
"dynamodb:BatchGetItem",
"dynamodb:BatchWriteItem",
"dynamodb:ConditionCheckItem",
"dynamodb:CreateTable",
"dynamodb:DeleteItem",
"dynamodb:DeleteTable",
"dynamodb:DescribeTable",
"dynamodb:GetItem",
"dynamodb:PutItem",
"dynamodb:Query",
"dynamodb:TagResource",
"dynamodb:UpdateTable"
],
"Resource": [
"arn:aws:dynamodb:${REGION}:${ACCOUNT_ID}:table/tecton-${DEPLOYMENT_NAME}*",
"arn:aws:dynamodb:${SATELLITE_REGION}:${ACCOUNT_ID}:table/tecton-${DEPLOYMENT_NAME}*"
]
},
{
"Sid": "DynamoDBCrossRegion",
"Effect": "Allow",
"Action": [
"dynamodb:CreateTableReplica",
"dynamodb:Scan",
"dynamodb:UpdateItem",
"dynamodb:DeleteTableReplica"
],
"Resource": [
"arn:aws:dynamodb:${SATELLITE_REGION}:${ACCOUNT_ID}:table/tecton-${DEPLOYMENT_NAME}*"
]
}
]
}
22 changes: 22 additions & 0 deletions templates/satellite_serving_dynamodb_policy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "CreateSatelliteServingDynamoDBServiceLinkedRole",
"Effect": "Allow",
"Action": [
"iam:CreateServiceLinkedRole"
],
"Resource": [
"arn:aws:iam::*:role/aws-service-role/replication.dynamodb.amazonaws.com/AWSServiceRoleForDynamoDBReplication*"
],
"Condition": {
"StringLike": {
"iam:AWSServiceName": [
"replication.dynamodb.amazonaws.com"
]
}
}
}
]
}