Skip to content

Commit 34a7507

Browse files
committed
feat: allow single filename deployement without source dir
1 parent 2319485 commit 34a7507

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

main.tf

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
locals {
22
source_dir = var.source_dir
3+
use_prebuilt_zip = var.filename != null
34
}
45

56
# Template files for user reference
@@ -38,9 +39,9 @@ resource "local_file" "makefile_template" {
3839
# ]
3940
# }
4041

41-
# Create zip package from source directory (only for Zip package type)
42+
# Create zip package from source directory (only for Zip package type and when not using prebuilt)
4243
data "archive_file" "lambda_zip" {
43-
count = var.package_type == "Zip" ? 1 : 0
44+
count = var.package_type == "Zip" && !local.use_prebuilt_zip ? 1 : 0
4445

4546
type = "zip"
4647
source_dir = local.source_dir
@@ -125,8 +126,8 @@ resource "aws_lambda_function" "this" {
125126
package_type = var.package_type
126127

127128
# Zip package configuration
128-
filename = var.package_type == "Zip" ? data.archive_file.lambda_zip[0].output_path : null
129-
source_code_hash = var.package_type == "Zip" ? data.archive_file.lambda_zip[0].output_base64sha256 : null
129+
filename = var.package_type == "Zip" ? (local.use_prebuilt_zip ? var.filename : data.archive_file.lambda_zip[0].output_path) : null
130+
source_code_hash = var.package_type == "Zip" ? (local.use_prebuilt_zip ? filebase64sha256(var.filename) : data.archive_file.lambda_zip[0].output_base64sha256) : null
130131
handler = var.package_type == "Zip" ? var.handler : null
131132
runtime = var.package_type == "Zip" ? var.runtime : null
132133

variables.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
variable "source_dir" {
22
type = string
33
description = "Path to the source directory containing Lambda function code"
4+
default = null
45
}
56

67
variable "handler" {
@@ -105,3 +106,9 @@ variable "image_config" {
105106
description = "Container image configuration"
106107
default = null
107108
}
109+
110+
variable "filename" {
111+
type = string
112+
description = "Path to pre-built zip file (alternative to source_dir)"
113+
default = null
114+
}

0 commit comments

Comments
 (0)