Skip to content

Commit 3ec4606

Browse files
committed
update lambda to support additional kms policy
1 parent e85f2a4 commit 3ec4606

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

examples/terraform-test/main.tf

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ module "lambda" {
5757
# Logging
5858
is_create_cloudwatch_log_group = true # Default is `true`
5959
cloudwatch_log_retention_in_days = 90 # Default is `90`
60-
cloudwatch_log_group_kms_key_arn = "arn:aws:kms:ap-southeast-1:562563527952:key/73ab5420-3183-4185-83de-19f6137cb13c"
61-
60+
additional_lambda_log_group_kms_policy = data.aws_iam_policy_document.allow_github_oidc.json
6261
# Env
6362
ssm_params = {}
6463
environment_variables = {
@@ -72,3 +71,27 @@ module "lambda" {
7271

7372
tags = var.generic_info.custom_tags
7473
}
74+
75+
76+
data "aws_iam_policy_document" "allow_github_oidc" {
77+
statement {
78+
sid = "AllowGitHubActionsEncryptDecrypt"
79+
effect = "Allow"
80+
81+
principals {
82+
type = "AWS"
83+
identifiers = [
84+
"arn:aws:iam::562563527952:role/oozou-internal-devops-github-action-oidc-role"
85+
]
86+
}
87+
88+
actions = [
89+
"kms:Encrypt",
90+
"kms:Decrypt",
91+
"kms:GenerateDataKey*",
92+
"kms:DescribeKey"
93+
]
94+
95+
resources = ["*"]
96+
}
97+
}

main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ module "cloudwatch_log_group_kms" {
340340
key_type = "service"
341341
append_random_suffix = true
342342
description = format("Secure Secrets Manager's service secrets for service %s", local.name)
343-
additional_policies = [data.aws_iam_policy_document.cloudwatch_log_group_kms_policy.json]
343+
additional_policies = [data.aws_iam_policy_document.cloudwatch_log_group_kms_policy.json, var.additional_lambda_log_group_kms_policy]
344344

345345
tags = merge(local.tags, { "Name" : format("%s-function-log-group", var.name) })
346346
}

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,9 @@ variable "ssm_params" {
213213
type = map(string)
214214
default = {}
215215
}
216+
217+
variable "additional_lambda_log_group_kms_policy" {
218+
description = "Additional IAM policy document for the Lambda log group KMS key."
219+
type = string
220+
default = null
221+
}

0 commit comments

Comments
 (0)