Skip to content

Commit

Permalink
added custom policies attachment
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Bakhmetev committed Sep 11, 2024
1 parent 4db934d commit 7128d90
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tf-aws-lambda/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
locals {
fully_qualified_name = "${module.name.id}-${var.function_name}"
partition = data.aws_partition.this[0].partition
custom_iam_policy_arns_map = length(var.custom_iam_policy_arns) > 0 ? { for i, arn in var.custom_iam_policy_arns : i => arn } : {}
}

module "name" {
Expand Down Expand Up @@ -43,6 +44,13 @@ resource "aws_iam_role_policy_attachment" "cloudwatch_logs" {
role = aws_iam_role.this.name
}

resource "aws_iam_role_policy_attachment" "custom" {
for_each = local.custom_iam_policy_arns_map

policy_arn = each.value
role = aws_iam_role.this.name
}

resource "aws_lambda_function" "this" {
function_name = local.fully_qualified_name
handler = var.handler
Expand Down
6 changes: 6 additions & 0 deletions tf-aws-lambda/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,10 @@ variable "lambda_environment" {
})
description = "Map of environment variables that are accessible from the function code during execution. If provided at least one key must be present."
default = null
}

variable "custom_iam_policy_arns" {
type = set(string)
description = "ARNs of custom policies to be attached to the lambda role"
default = []
}

0 comments on commit 7128d90

Please sign in to comment.