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

feat: Change to use of managed IAM policy for ecs tasks with path attribute support over inline role policy #266

Closed
wants to merge 1 commit into from
Closed
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 main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ module "service" {
tasks_iam_role_description = try(each.value.tasks_iam_role_description, null)
tasks_iam_role_permissions_boundary = try(each.value.tasks_iam_role_permissions_boundary, null)
tasks_iam_role_tags = try(each.value.tasks_iam_role_tags, {})
tasks_iam_policy_path = try(each.value.tasks_iam_policy_path, null)
tasks_iam_role_policies = lookup(each.value, "tasks_iam_role_policies", {})
tasks_iam_role_statements = lookup(each.value, "tasks_iam_role_statements", {})

Expand Down
13 changes: 11 additions & 2 deletions modules/service/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -1024,13 +1024,22 @@ data "aws_iam_policy_document" "tasks" {
}
}

resource "aws_iam_role_policy" "tasks" {
resource "aws_iam_policy" "tasks" {
count = local.create_tasks_iam_role && (length(var.tasks_iam_role_statements) > 0 || var.enable_execute_command) ? 1 : 0

name = var.tasks_iam_role_use_name_prefix ? null : local.tasks_iam_role_name
name_prefix = var.tasks_iam_role_use_name_prefix ? "${local.tasks_iam_role_name}-" : null
description = coalesce(var.tasks_iam_role_description, "Task role IAM policy")
policy = data.aws_iam_policy_document.tasks[0].json
role = aws_iam_role.tasks[0].id
path = var.tasks_iam_policy_path
tags = merge(var.tags, var.tasks_iam_role_tags)
}

resource "aws_iam_role_policy_attachment" "tasks_policy" {
count = local.create_tasks_iam_role && (length(var.tasks_iam_role_statements) > 0 || var.enable_execute_command) ? 1 : 0

role = aws_iam_role.tasks[0].name
policy_arn = aws_iam_policy.tasks[0].arn
}

################################################################################
Expand Down
6 changes: 6 additions & 0 deletions modules/service/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,12 @@ variable "tasks_iam_role_statements" {
default = {}
}

variable "tasks_iam_policy_path" {
description = "Path for the tasks iam policy"
type = string
default = null
}

################################################################################
# Task Set
################################################################################
Expand Down
Loading