Skip to content

Commit a759b04

Browse files
eli-540 attach roles to lambda and external role
1 parent cd01ca8 commit a759b04

File tree

4 files changed

+41
-8
lines changed

4 files changed

+41
-8
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
output "aws_hashing_secret_arn" {
2+
value = aws_secretsmanager_secret.hashing_secret.arn
3+
}

infrastructure/modules/secrets_manager/variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
variable "external_write_access_role_arn" {
2-
description = "Arn of the external write access role to provide secret manager access"
3-
type = string
2+
description = "List of ARNs for external write access roles"
3+
type = list(string)
44
}
55

66
variable "eligibility_lambda_role_arn" {

infrastructure/stacks/api-layer/iam_policies.tf

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,3 +530,34 @@ resource "aws_iam_role_policy" "external_audit_kms_access_policy" {
530530
role = aws_iam_role.write_access_role[count.index].id
531531
policy = data.aws_iam_policy_document.external_role_s3_audit_kms_access_policy.json
532532
}
533+
534+
# IAM policy document for Lambda secret access
535+
data "aws_iam_policy_document" "secrets_access_policy" {
536+
statement {
537+
effect = "Allow"
538+
539+
actions = [
540+
"secretsmanager:GetSecretValue",
541+
"secretsmanager:DescribeSecret",
542+
]
543+
544+
resources = [
545+
module.secrets_manager.aws_hashing_secret_arn
546+
]
547+
}
548+
}
549+
550+
# Attach secret read policy to Lambda role
551+
resource "aws_iam_role_policy" "lambda_secret_read_policy_attachment" {
552+
name = "LambdaSecretReadAccess"
553+
role = aws_iam_role.eligibility_lambda_role.id
554+
policy = data.aws_iam_policy_document.secrets_access_policy.json
555+
}
556+
557+
# Attach secret read policy to external write role
558+
resource "aws_iam_role_policy" "external_secret_read_policy_attachment" {
559+
count = length(aws_iam_role.write_access_role)
560+
name = "ExternalSecretReadAccess"
561+
role = aws_iam_role.write_access_role[count.index].id
562+
policy = data.aws_iam_policy_document.secrets_access_policy.json
563+
}
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
module "secrets_manager" {
22
source = "../../modules/secrets_manager"
3-
count = length(aws_iam_role.write_access_role)
4-
external_write_access_role_arn = aws_iam_role.write_access_role[count.index].arn
5-
environment = var.environment
6-
stack_name = local.stack_name
7-
workspace = terraform.workspace
8-
eligibility_lambda_role_arn = aws_iam_role.eligibility_lambda_role.arn
3+
external_write_access_role_arn = aws_iam_role.write_access_role[*].arn
4+
environment = var.environment
5+
stack_name = local.stack_name
6+
workspace = terraform.workspace
7+
eligibility_lambda_role_arn = aws_iam_role.eligibility_lambda_role.arn
98
}

0 commit comments

Comments
 (0)