Skip to content
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
28 changes: 28 additions & 0 deletions define-policies.tf
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,21 @@ resource "aws_iam_role_policy_attachment" "attach-allow-elb" {
# name = "ecsTaskExecutionRole"
# }

data "aws_iam_policy_document" "ecs-service-allow-secrets-manager" {
count = "${var.aws_secrets_manager_secret_arn != "" ? 1 : 0}"
statement {
effect = "Allow"

actions = [
"secretsmanager:GetSecretValue"
]

resources = [
"${var.aws_secrets_manager_secret_arn}"
]
}
}

data "aws_iam_policy_document" "ecs-task-access-ecr" {
statement {
effect = "Allow"
Expand Down Expand Up @@ -116,6 +131,13 @@ data "aws_iam_policy_document" "ecs-task-access-cloudwatch" {
}
}

resource "aws_iam_policy" "ecs-service-allow-secrets-manager" {
count = "${var.aws_secrets_manager_secret_arn != "" ? 1 : 0}"
name = "ecs-service-allow-secrets-manager-${var.project}-${var.service}-${var.environment}"
description = "ECS Service policy to access Secrets Manager"
policy = "${data.aws_iam_policy_document.ecs-service-allow-secrets-manager.json}"
}

resource "aws_iam_policy" "ecs-task-access-ecr" {
name = "ecs-task-allow-ec2-${var.project}-${var.service}-${var.environment}"
description = "ECS task policy to access ECR"
Expand Down Expand Up @@ -150,6 +172,12 @@ EOF
tags = "${merge(local.default_tags, var.tags)}"
}

resource "aws_iam_role_policy_attachment" "attach-allow-secrets-manager" {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

it should be done in your terraform service.

count = "${var.aws_secrets_manager_secret_arn != "" ? 1 : 0}"
role = "${aws_iam_role.ecs-task-execution.name}"
policy_arn = "${aws_iam_policy.ecs-service-allow-secrets-manager.arn}"
}

resource "aws_iam_role_policy_attachment" "attach-allow-ecr" {
role = "${aws_iam_role.ecs-task-execution.name}"
policy_arn = "${aws_iam_policy.ecs-task-access-ecr.arn}"
Expand Down
5 changes: 5 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ variable "task_role_arn" {
default = ""
}

variable "aws_secrets_manager_secret_arn" {
description = "ARN of specific AWS Secrets Manager secret which stores credentials for accessing private docker images registry"
default = ""
}

variable "tags" {
type = "map"
description = "Additional tags for all resources"
Expand Down