Skip to content

Commit b502b00

Browse files
committed
feat: Support deployment package via S3
1 parent 9d671a1 commit b502b00

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

main.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ resource "aws_lambda_function" "this" {
137137
# configuration and Terraform will show a perpetual difference of adding the key.
138138
kms_key_arn = var.environment == null ? null : var.lambda_kms_key_arn
139139

140+
s3_bucket = var.s3_bucket
141+
s3_key = var.s3_key
142+
s3_object_version = var.s3_object_version
143+
140144
tags = var.tags
141145

142146
lifecycle {

s3.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
locals {
2+
create_s3_object = (
3+
!(var.s3_bucket == null || var.s3_key == null || var.output_path == null)
4+
)
5+
}
6+
7+
resource "aws_s3_object" "this" {
8+
count = var.create_s3_object ? 1 : 0
9+
10+
bucket = var.s3_bucket
11+
key = var.s3_key
12+
source = var.output_path
13+
14+
etag = filemd5(var.output_path)
15+
}

variables.tf

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,38 @@ variable "build_triggers" {
2727
}
2828

2929
variable "source_dir" {
30-
description = "A path to the directory which contains source files to be archived. If set to `null`, then no archive file is created."
30+
description = "A path to the directory which contains source files to be archived into a deployment package. If set to `null`, then no archive file is created."
3131
type = string
32+
default = null
3233
}
3334

3435
variable "output_path" {
35-
description = "A path to the archive file which will be uploaded to AWS. If `source_dir` is not `null`, then a file is created at `output_path` containing the archived contents of `source_dir`."
36+
description = "A path to the deployment archive which will be uploaded to AWS. If `source_dir` is not `null`, then a file is created at `output_path` containing the archived contents of `source_dir`."
37+
type = string
38+
default = null
39+
}
40+
41+
variable "s3_bucket" {
42+
description = "An existing S3 bucket, containing the function's deployment package. If `output_path` is also specified, the archive will be uploaded here."
43+
type = string
44+
default = null
45+
}
46+
47+
variable "s3_key" {
48+
description = "S3 key of an object containing the function's deployment package. If `output_path` is also specified, the archive will be uploaded here."
3649
type = string
50+
default = null
51+
}
52+
53+
variable "s3_object_version" {
54+
description = "S3 object version containing the function's deployment package."
55+
type = string
56+
default = null
3757
}
3858

3959
variable "exclude_files" {
4060
description = <<DESC
41-
A list of directories or folders to ignore, e.g.
61+
A list of source directories or folders to ignore when creating the archive, e.g.
4262
exclude_files = ["test", "src/**/*.ts"]
4363
DESC
4464
type = list(string)

0 commit comments

Comments
 (0)