Skip to content

Commit

Permalink
Allow to build the lambda using an external image instead of the lamb…
Browse files Browse the repository at this point in the history
…da code provided by the module
  • Loading branch information
nnovaeshc committed Jul 23, 2024
1 parent 953aaf6 commit b47b9ee
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
11 changes: 7 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ data "aws_iam_policy_document" "lifecycle_policy" {
}

data "archive_file" "autoscale" {
count = var.lambda_image_uri != null ? 0 : 1
type = "zip"
source_file = "${path.module}/lambda/autoscale/autoscale.py"
output_path = "${path.module}/lambda/dist/autoscale.zip"
Expand All @@ -106,12 +107,14 @@ data "archive_file" "autoscale" {
resource "aws_lambda_function" "autoscale_handling" {
depends_on = [aws_sns_topic.autoscale_handling]

filename = data.archive_file.autoscale.output_path
filename = var.lambda_image_uri != null ? null : data.archive_file.autoscale[0].output_path
function_name = "${var.vpc_name}-${var.autoscale_handler_unique_identifier}"
role = aws_iam_role.autoscale_handling.arn
handler = "autoscale.lambda_handler"
runtime = "python3.8"
source_code_hash = filebase64sha256(data.archive_file.autoscale.output_path)
handler = var.lambda_image_uri != null ? null : "autoscale.lambda_handler"
runtime = var.lambda_image_uri != null ? null : "python3.8"
source_code_hash = var.lambda_image_uri != null ? null : filebase64sha256(data.archive_file.autoscale[0].output_path)
image_uri = var.lambda_image_uri != null ? var.lambda_image_uri : null
package_type = var.lambda_image_uri != null ? "Image" : "Zip"
description = "Handles DNS for autoscaling groups by receiving autoscaling notifications and setting/deleting records from route53"
environment {
variables = {
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ variable "route53_record_ttl" {
default = 300
type = number
}

variable "lambda_image_uri" {
default = null
type = string
description = "The URI of the Lambda image"
}

0 comments on commit b47b9ee

Please sign in to comment.