Skip to content

Commit 9c11d95

Browse files
authored
feat: Allow user to configure custom IAM policy for ECS Task Execution Role (#7)
1 parent a4baf6a commit 9c11d95

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

main.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@ resource "aws_iam_role_policy_attachment" "ecs_task_execution_role_policy_attach
1111
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
1212
}
1313

14+
resource "aws_iam_policy" "ecs_task_execution_role_custom_policy" {
15+
count = length(var.ecs_task_execution_role_custom_policy) > 0 ? 1 : 0
16+
name = "${var.name_prefix}-ecs-task-execution-role-custom-policy"
17+
description = "A custom policy for ${var.name_prefix}-ecs-task-execution-role IAM Role"
18+
19+
policy = var.ecs_task_execution_role_custom_policy
20+
}
21+
22+
resource "aws_iam_role_policy_attachment" "ecs_task_execution_role_custom_policy" {
23+
count = length(var.ecs_task_execution_role_custom_policy) > 0 ? 1 : 0
24+
role = aws_iam_role.ecs_task_execution_role.name
25+
policy_arn = aws_iam_policy.ecs_task_execution_role_custom_policy[*].arn
26+
}
27+
1428
#------------------------------------------------------------------------------
1529
# ECS Task Definition
1630
#------------------------------------------------------------------------------

variables.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,12 @@ variable "task_role_arn" {
322322
default = null
323323
}
324324

325+
variable "ecs_task_execution_role_custom_policy" {
326+
description = "(Optional) A custom policy to attach to the ECS task execution role. For example for reading secrets from AWS Systems Manager Parameter Store or Secrets Manager"
327+
type = string
328+
default = null
329+
}
330+
325331
variable "placement_constraints" {
326332
description = "(Optional) A set of placement constraints rules that are taken into consideration during task placement. Maximum number of placement_constraints is 10. This is a list of maps, where each map should contain \"type\" and \"expression\""
327333
type = list
@@ -353,3 +359,4 @@ variable "volumes" {
353359
}))
354360
default = []
355361
}
362+

0 commit comments

Comments
 (0)