Skip to content

Commit

Permalink
Merge pull request #5161 from ministryofjustice/csr/lambda-iam-role
Browse files Browse the repository at this point in the history
Csr/lambda iam role
  • Loading branch information
haitchison authored Feb 23, 2024
2 parents afb1184 + 3a561c5 commit ed4b4cc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
29 changes: 27 additions & 2 deletions terraform/environments/corporate-staff-rostering/iam.tf
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,31 @@ resource "aws_iam_role" "lambda-ad-role" {
assume_role_policy = data.aws_iam_policy_document.lambda_assume_role_policy.json
}

resource "aws_iam_policy" "lambda-ad-policy" {
name = "LambdaADObjectCleanUpPolicy"
description = "Policy to grant AD lambda function VPC access"

policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"ec2:CreateNetworkInterface",
"ec2:Describe*",
"ec2:DeleteNetworkInterface",
"ec2:AssignPrivateIpAddresses",
"ec2:UnassignPrivateIpAddresses"
]
Effect = "Allow"
Resource = "*"
},
]
})
}

data "aws_iam_policy" "HmppsDomainSecrets" {
name = "HmppsDomainSecretsPolicy"
}
Expand All @@ -82,9 +107,9 @@ resource "aws_iam_role_policy_attachment" "lambda_kms" {
policy_arn = data.aws_iam_policy.BusinessUnitKmsCmk.arn
}

resource "aws_iam_role_policy_attachment" "lambda-vpc-attachment" {
resource "aws_iam_role_policy_attachment" "lambda-ad-policy-attachment" {
role = aws_iam_role.lambda-ad-role.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole"
policy_arn = aws_iam_policy.lambda-ad-policy.arn
}


Expand Down
2 changes: 1 addition & 1 deletion terraform/environments/corporate-staff-rostering/lambda.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module "ad-clean-up-lambda" {
source_code_hash = filebase64sha256("${path.module}/lambda/ad-clean-up/deployment_package.zip")
handler = "lambda_function.lambda_handler"
runtime = "python3.12"
timeout = 60

create_role = false
lambda_role = aws_iam_role.lambda-ad-role.arn
Expand Down Expand Up @@ -79,7 +80,6 @@ module "lambda_cw_logs_xml_to_json" {
source_code_hash = filebase64sha256("${path.module}/lambda/cw-xml-to-json/deployment_package.zip")
runtime = "python3.12"
handler = "lambda_function.lambda_handler"
timeout = 60

policy_json_attached = true
policy_json = jsonencode({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ terraform {
version = "~> 3.0"
source = "hashicorp/http"
}
archive = {
source = "hashicorp/archive"
}
}
required_version = "~> 1.0"
}

0 comments on commit ed4b4cc

Please sign in to comment.