Skip to content

Commit fa19e0b

Browse files
chrisbloerobg-nhs
andauthored
[NDR-234] Virus Scanner upgrade and on-demand lambda-VPC attachment (#404)
* [NDR-234] Virus Scanner upgrade and on-demand lambda-VPC attachment * Fix vpc_security_group_ids indexing in Terraform config * Fix formatting of version line in virusscanner.tf * Rename AWS IAM policy data source for VPC access * Format variable definitions in variable.tf --------- Co-authored-by: robg-nhs <[email protected]>
1 parent bd0fc90 commit fa19e0b

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

infrastructure/lambda-document-upload-check.tf

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module "document_upload_check_lambda" {
1010
aws_iam_policy.ssm_access_policy.policy,
1111
module.lloyd_george_reference_dynamodb_table.dynamodb_read_policy_document,
1212
module.lloyd_george_reference_dynamodb_table.dynamodb_write_policy_document,
13+
data.aws_iam_policy.aws_lambda_vpc_access_execution_role.policy
1314
]
1415
kms_deletion_window = var.kms_deletion_window
1516
rest_api_id = null
@@ -26,6 +27,8 @@ module "document_upload_check_lambda" {
2627
lambda_timeout = 900
2728
is_gateway_integration_needed = false
2829
is_invoked_from_gateway = false
30+
vpc_subnet_ids = length(data.aws_security_groups.virus_scanner_api.ids) == 1 ? module.ndr-vpc-ui.private_subnets : []
31+
vpc_security_group_ids = length(data.aws_security_groups.virus_scanner_api.ids) == 1 ? [data.aws_security_groups.virus_scanner_api.ids[0]] : []
2932
depends_on = [
3033
aws_api_gateway_rest_api.ndr_doc_store_api,
3134
module.ndr-bulk-staging-store,
@@ -34,6 +37,16 @@ module "document_upload_check_lambda" {
3437
]
3538
}
3639

40+
data "aws_iam_policy" "aws_lambda_vpc_access_execution_role" {
41+
arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole"
42+
}
43+
44+
data "aws_security_groups" "virus_scanner_api" {
45+
filter {
46+
name = "description"
47+
values = ["Security Group for CloudStorageSec Api Agent"]
48+
}
49+
}
3750

3851
resource "aws_s3_bucket_notification" "document_upload_check_lambda_trigger" {
3952
count = 1
@@ -53,4 +66,3 @@ resource "aws_lambda_permission" "document_upload_check_lambda" {
5366
principal = "s3.amazonaws.com"
5467
source_arn = "arn:aws:s3:::${module.ndr-bulk-staging-store.bucket_id}"
5568
}
56-

infrastructure/modules/lambda/main.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,34 @@ resource "aws_lambda_function" "lambda" {
1111
memory_size = var.memory_size
1212
reserved_concurrent_executions = var.reserved_concurrent_executions
1313
kms_key_arn = aws_kms_key.lambda.arn
14+
1415
ephemeral_storage {
1516
size = var.lambda_ephemeral_storage
1617
}
18+
1719
environment {
1820
variables = var.lambda_environment_variables
1921
}
22+
23+
vpc_config {
24+
subnet_ids = var.vpc_subnet_ids
25+
security_group_ids = var.vpc_security_group_ids
26+
}
27+
2028
layers = local.lambda_layers
29+
2130
lifecycle {
2231
ignore_changes = [
2332
# These are required as Lambdas are deployed via the CI/CD pipelines
2433
source_code_hash,
2534
layers
2635
]
2736
}
37+
38+
depends_on = [
39+
aws_iam_role_policy_attachment.default_policies,
40+
aws_iam_role_policy_attachment.lambda_execution_policy
41+
]
2842
}
2943

3044
resource "aws_cloudwatch_log_group" "lambda_logs" {

infrastructure/modules/lambda/variable.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,14 @@ variable "kms_deletion_window" {
118118
default = 30
119119
}
120120

121+
variable "vpc_subnet_ids" {
122+
description = "List of subnet IDs associated with the Lambda function, if it sits within a VPC."
123+
type = list(string)
124+
default = []
125+
}
126+
127+
variable "vpc_security_group_ids" {
128+
description = "List of security group IDs associated with the Lambda function, if it sits within a VPC."
129+
type = list(string)
130+
default = []
131+
}

infrastructure/virusscanner.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ module "cloud_storage_security" {
6868
count = local.is_production ? 1 : 0
6969

7070
source = "cloudstoragesec/cloud-storage-security/aws"
71-
version = "1.8.7+css9.01.003"
71+
version = "1.8.8+css9.02.000" # Check https://help.cloudstoragesec.com/release-notes/latest-v9 for updates
7272
cidr = [var.cloud_security_console_black_hole_address] # This is a reserved address that does not lead anywhere to make sure CloudStorageSecurity console is not available
7373
email = data.aws_ssm_parameter.cloud_security_admin_email.value
7474
subnet_a_id = aws_subnet.virus_scanning_a[0].id

0 commit comments

Comments
 (0)