From 6d1250f53bd138f7b142fcb9cae7194010d9baca Mon Sep 17 00:00:00 2001 From: Adam Sherwood Date: Wed, 4 Aug 2021 15:02:41 +0200 Subject: [PATCH 1/2] Let the user pick the object key. This allows more flexibility in how the user chooses to arrange versions and builds in S3. It also changes the default archive to lambda.zip since this is the upstream default. --- README.md | 3 +-- anti-virus-scan.tf | 2 +- anti-virus-update.tf | 2 +- variables.tf | 11 +++-------- 4 files changed, 6 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 74af718..0ae7fbe 100644 --- a/README.md +++ b/README.md @@ -51,8 +51,7 @@ module "s3_anti_virus" { name_update = "s3-anti-virus-updates" lambda_s3_bucket = "lambda-builds-us-west-2" - lambda_version = "2.0.0" - lambda_package = "anti-virus" + lambda_package_key = "lambda.zip" av_update_minutes = "180" av_scan_buckets = ["bucket-name"] diff --git a/anti-virus-scan.tf b/anti-virus-scan.tf index 2254d3a..afb60b7 100644 --- a/anti-virus-scan.tf +++ b/anti-virus-scan.tf @@ -164,7 +164,7 @@ resource "aws_lambda_function" "main_scan" { description = "Scans s3 objects with clamav for viruses." s3_bucket = var.lambda_s3_bucket - s3_key = "${var.lambda_package}/${var.lambda_version}/${var.lambda_package}.zip" + s3_key = var.lambda_package_key function_name = var.name_scan role = aws_iam_role.main_scan.arn diff --git a/anti-virus-update.tf b/anti-virus-update.tf index 0277344..72a97c5 100644 --- a/anti-virus-update.tf +++ b/anti-virus-update.tf @@ -123,7 +123,7 @@ resource "aws_lambda_function" "main_update" { description = "Updates clamav definitions stored in s3." s3_bucket = var.lambda_s3_bucket - s3_key = "${var.lambda_package}/${var.lambda_version}/${var.lambda_package}.zip" + s3_key = var.lambda_package_key function_name = var.name_update role = aws_iam_role.main_update.arn diff --git a/variables.tf b/variables.tf index 3ddb52a..1f7175b 100644 --- a/variables.tf +++ b/variables.tf @@ -21,15 +21,10 @@ variable "lambda_s3_bucket" { type = string } -variable "lambda_version" { - description = "The version the Lambda function to deploy." +variable "lambda_package_key" { + description = "The object key for the lambda distribution. Defaults to lambda.zip since this is build by default upstream." type = string -} - -variable "lambda_package" { - description = "The name of the lambda package. Used for a directory tree and zip file." - type = string - default = "anti-virus" + default = "lambda.zip" } variable "memory_size" { From 20fee820df8c4445ae40fbf83f1b2819d1f852fb Mon Sep 17 00:00:00 2001 From: Adam Sherwood Date: Mon, 30 Aug 2021 11:08:35 +0200 Subject: [PATCH 2/2] Add back variables to maintain compatibility. Override, default prefix construction when lambda_key_prefix is given. --- anti-virus-scan.tf | 2 +- anti-virus-update.tf | 2 +- main.tf | 4 ++++ variables.tf | 14 ++++++++++++-- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/anti-virus-scan.tf b/anti-virus-scan.tf index afb60b7..19fce09 100644 --- a/anti-virus-scan.tf +++ b/anti-virus-scan.tf @@ -164,7 +164,7 @@ resource "aws_lambda_function" "main_scan" { description = "Scans s3 objects with clamav for viruses." s3_bucket = var.lambda_s3_bucket - s3_key = var.lambda_package_key + s3_key = local.lambda_package_key function_name = var.name_scan role = aws_iam_role.main_scan.arn diff --git a/anti-virus-update.tf b/anti-virus-update.tf index 72a97c5..a09ad08 100644 --- a/anti-virus-update.tf +++ b/anti-virus-update.tf @@ -123,7 +123,7 @@ resource "aws_lambda_function" "main_update" { description = "Updates clamav definitions stored in s3." s3_bucket = var.lambda_s3_bucket - s3_key = var.lambda_package_key + s3_key = local.lambda_package_key function_name = var.name_update role = aws_iam_role.main_update.arn diff --git a/main.tf b/main.tf index be3d1f4..ba7c599 100644 --- a/main.tf +++ b/main.tf @@ -6,3 +6,7 @@ data "aws_caller_identity" "current" {} # The AWS partition (commercial or govcloud) data "aws_partition" "current" {} + +locals { + lambda_package_key = var.lambda_package_key != null ? var.lambda_package_key : "${var.lambda_package}/${var.lambda_version}/${var.lambda_package}.zip" +} diff --git a/variables.tf b/variables.tf index 1f7175b..fd46a9f 100644 --- a/variables.tf +++ b/variables.tf @@ -21,10 +21,20 @@ variable "lambda_s3_bucket" { type = string } +variable "lambda_version" { + description = "The version the Lambda function to deploy." +} + +variable "lambda_package" { + description = "The name of the lambda package. Used for a directory tree and zip file." + type = string + default = "anti-virus" +} + variable "lambda_package_key" { - description = "The object key for the lambda distribution. Defaults to lambda.zip since this is build by default upstream." + description = "The object key for the lambda distribution. If given, the value is used as the key in lieu of the value constructed using `lambda_package` and `lambda_version`." type = string - default = "lambda.zip" + default = null } variable "memory_size" {