Skip to content

Commit

Permalink
Sre 1854 refactor payments api task def to load secrets directly from…
Browse files Browse the repository at this point in the history
… ssm or secrets manager (#35)

* Add secretOptions to the container def
  • Loading branch information
SaiPrasannaGopularam authored Nov 29, 2023
1 parent a94ea1f commit 1c84032
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
10 changes: 8 additions & 2 deletions data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@ data "aws_iam_policy_document" "task_execution_role_policy" {
statement {
effect = "Allow"
actions = ["secretsmanager:GetSecretValue"]
resources = ["${var.docker_secret}"]
resources = concat([var.docker_secret], var.secret_arns)
}

statement {
effect = "Allow"
actions = ["kms:Decrypt"]
resources = [var.encryption_key]
}

statement {
Expand All @@ -83,6 +89,6 @@ data "aws_iam_policy_document" "task_execution_role_policy" {
"ecs:ExecuteCommand",
"ecs:DescribeTasks"
]
resources = [aws_ecs_task_definition.task.arn]
resources = ["${aws_ecs_task_definition.task.arn}:*"]
}
}
1 change: 1 addition & 0 deletions files/container_definition.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"volumesFrom": [],
"logConfiguration": {
"logDriver": "awslogs",
${secretsoptions}
"options": {
"awslogs-group": "${awslogs_group}",
"awslogs-region": "${awslogs_region}",
Expand Down
3 changes: 3 additions & 0 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ locals {
}
}

secrets = length(var.secrets) > 0 ? "\"secretOptions\": ${jsonencode(var.secrets)}," : ""

container_def = templatefile("${path.module}/files/container_definition.json",
{
service_identifier = var.service_identifier
Expand All @@ -38,6 +40,7 @@ locals {
awslogs_region = data.aws_region.region.name
awslogs_group = aws_cloudwatch_log_group.task.name
awslogs_stream_prefix = var.service_identifier
secretsoptions = local.secrets
}
)
}
15 changes: 15 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,18 @@ variable "entrypoint" {
description = "The entry point that's passed to the container. Use [ \"sleep\", \"60\" ], when enabling exec command"
default = ""
}

variable "secrets" {
description = "Secrets to be passed to the container environment"
default = ""
}

variable "secret_arns" {
description = "Arn of the secrets that are passed to the container environment"
default = null
}

variable "encryption_key" {
description = "Kms key to decrypt secrets"
default = null
}

0 comments on commit 1c84032

Please sign in to comment.