Skip to content

Commit

Permalink
Merge pull request #9 from gchamon/feature/pass-precompiled-lambda-code
Browse files Browse the repository at this point in the history
possibility to pass precompiled lambda zip and skip compilation
  • Loading branch information
Gabriel Chamon Araujo authored Oct 22, 2019
2 parents 0f8dc9b + 64407ce commit ad6259f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Developed using version `0.12.9`. Should work on `0.12.x`
| buckets-to-scan | List of bucket names to be scanned by the antivirus | list(string) | - | yes |
| scanner-environment-variables | Custom environment variables for the scanner function | map(string) | {} | no |
| updater-environment-variables | Custom environment variables for the definitions update function | map(string) | {} | no |
| antivirus-lambda-code | Optional argument to provide precompiled zip file containing the lambda code, skipping the built in compilation process | string | null | no |
| allow-public-access | If true, contents of the bucket in which the antivirus definitions are saved will be public. Good for sharing the same definitions across multiple accounts | bool | false | no |
| antivirus-update-rate | Configures the antivirus update rate. Syntax is the same of cloudwatch rate schedule expression for rules | string | "3 hours" | no |

Expand Down
12 changes: 11 additions & 1 deletion build-antivirus-from-source.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
resource "null_resource" "build-antivirus-from-source" {
count = (
var.antivirus-lambda-code == null
? 1
: 0
)

provisioner "local-exec" {
command = "bash ${path.module}/scripts/build-antivirus-from-source.sh"
}
Expand All @@ -14,5 +20,9 @@ resource "aws_s3_bucket_object" "antivirus-code" {
bucket = aws_s3_bucket.antivirus-code.bucket
key = "lambda.zip"

source = "/tmp/bucket-antivirus-function/build/lambda.zip"
source = (
var.antivirus-lambda-code == null
? "/tmp/bucket-antivirus-function/build/lambda.zip"
: pathexpand(var.antivirus-lambda-code)
)
}
8 changes: 6 additions & 2 deletions policies/bucket-antivirus-update.json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@
"s3:GetObjectTagging",
"s3:PutObject",
"s3:PutObjectTagging",
"s3:PutObjectVersionTagging"
"s3:PutObjectVersionTagging",
"s3:ListBucket"
],
"Effect":"Allow",
"Resource":"arn:aws:s3:::${bucket-name}/*"
"Resource":[
"arn:aws:s3:::${bucket-name}/*",
"arn:aws:s3:::${bucket-name}"
]
}
]
}
4 changes: 2 additions & 2 deletions update-function.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ module "trigger-antivirus-update-periodically" {
source = "./modules/periodic-lambda-trigger"

lambda-function = aws_lambda_function.antivirus-update
schedule-expression = "rate(${var.antivirus-update-rate}})"
schedule-expression = "rate(${var.antivirus-update-rate})"
description = "Update antivirus definitions every ${var.antivirus-update-rate}"
}
}
8 changes: 7 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ variable "updater-environment-variables" {
default = {}
}

variable "antivirus-lambda-code" {
description = "Optional argument to provide precompiled zip file containing the lambda code, skipping the built in compilation process"
type = string
default = null
}

variable "allow-public-access" {
description = "If true, contents of the bucket in which the antivirus definitions are saved will be public. Good for sharing the same definitions across multiple accounts."
type = bool
Expand All @@ -25,4 +31,4 @@ variable "antivirus-update-rate" {
description = "Configures the antivirus update rate. Syntax is the same of cloudwatch rate schedule expression for rules"
type = string
default = "3 hours"
}
}

0 comments on commit ad6259f

Please sign in to comment.