Skip to content
Merged
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
1 change: 1 addition & 0 deletions ops/mainnet/mason/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ module "mark_invoice_handler" {
dd_api_key = local.mark_config.dd_api_key
vpc_flow_logs_role_arn = module.iam.vpc_flow_logs_role_arn
execution_role_arn = data.aws_iam_role.ecr_admin_role.arn
task_role_arn = module.iam.ecs_task_role_arn
cluster_id = module.ecs.ecs_cluster_id
vpc_id = module.network.vpc_id
lb_subnets = module.network.public_subnets
Expand Down
88 changes: 88 additions & 0 deletions ops/modules/iam/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ data "aws_iam_role" "vpc_flow_logs" {
name = "vpc_flow_logs_role"
}

data "aws_region" "current" {}

resource "aws_iam_role_policy" "lambda_ssm_policy" {
name = "mark-lambda-ssm-policy-${var.environment}-${var.stage}"
role = aws_iam_role.lambda_role.id
Expand Down Expand Up @@ -79,3 +81,89 @@ resource "aws_iam_role_policy" "lambda_s3_policy" {
}
EOF
}

# ECS Task Role - for application-level AWS API calls (SSM, S3, etc.)
resource "aws_iam_role" "ecs_task_role" {
name = "mark-ecs-task-role-${var.environment}-${var.stage}"

assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "ecs-tasks.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF

tags = {
Environment = var.environment
Stage = var.stage
Domain = var.domain
}
}

resource "aws_iam_role_policy" "ecs_task_ssm_policy" {
name = "mark-ecs-task-ssm-policy-${var.environment}-${var.stage}"
role = aws_iam_role.ecs_task_role.id

policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ssm:DescribeParameters",
"ssm:GetParameter",
"ssm:GetParameters",
"ssm:GetParametersByPath"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"kms:Decrypt"
],
"Resource": "*",
"Condition": {
"StringEquals": {
"kms:ViaService": "ssm.${data.aws_region.current.name}.amazonaws.com"
}
}
}
]
}
EOF
}

resource "aws_iam_role_policy" "ecs_task_s3_policy" {
name = "mark-ecs-task-s3-policy-${var.environment}-${var.stage}"
role = aws_iam_role.ecs_task_role.id

policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::*-rebalance-config",
"arn:aws:s3:::*-rebalance-config/*"
]
}
]
}
EOF
}
5 changes: 5 additions & 0 deletions ops/modules/iam/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ output "lambda_role_arn" {
value = aws_iam_role.lambda_role.arn
}

output "ecs_task_role_arn" {
description = "The ARN of the ECS task IAM role"
value = aws_iam_role.ecs_task_role.arn
}

output "vpc_flow_logs_role_arn" {
description = "ARN of the VPC Flow Logs IAM role"
value = data.aws_iam_role.vpc_flow_logs.arn
Expand Down
1 change: 1 addition & 0 deletions ops/modules/service/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ resource "aws_ecs_task_definition" "service" {
cpu = var.cpu
memory = var.memory
execution_role_arn = var.execution_role_arn
task_role_arn = var.task_role_arn

container_definitions = jsonencode(concat(
var.init_container_enabled ? [
Expand Down
6 changes: 6 additions & 0 deletions ops/modules/service/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ variable "execution_role_arn" {
type = string
}

variable "task_role_arn" {
description = "ARN of the ECS task role (for application AWS API calls)"
type = string
default = null
}

variable "cluster_id" {
description = "ID of the ECS cluster"
type = string
Expand Down