Skip to content

Commit

Permalink
feat: Support deployment package via S3
Browse files Browse the repository at this point in the history
  • Loading branch information
baolsen committed Dec 12, 2022
1 parent 9d671a1 commit b502b00
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
4 changes: 4 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ resource "aws_lambda_function" "this" {
# configuration and Terraform will show a perpetual difference of adding the key.
kms_key_arn = var.environment == null ? null : var.lambda_kms_key_arn

s3_bucket = var.s3_bucket
s3_key = var.s3_key
s3_object_version = var.s3_object_version

tags = var.tags

lifecycle {
Expand Down
15 changes: 15 additions & 0 deletions s3.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
locals {
create_s3_object = (
!(var.s3_bucket == null || var.s3_key == null || var.output_path == null)
)
}

resource "aws_s3_object" "this" {
count = var.create_s3_object ? 1 : 0

bucket = var.s3_bucket
key = var.s3_key
source = var.output_path

etag = filemd5(var.output_path)
}
26 changes: 23 additions & 3 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,38 @@ variable "build_triggers" {
}

variable "source_dir" {
description = "A path to the directory which contains source files to be archived. If set to `null`, then no archive file is created."
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."
type = string
default = null
}

variable "output_path" {
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`."
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`."
type = string
default = null
}

variable "s3_bucket" {
description = "An existing S3 bucket, containing the function's deployment package. If `output_path` is also specified, the archive will be uploaded here."
type = string
default = null
}

variable "s3_key" {
description = "S3 key of an object containing the function's deployment package. If `output_path` is also specified, the archive will be uploaded here."
type = string
default = null
}

variable "s3_object_version" {
description = "S3 object version containing the function's deployment package."
type = string
default = null
}

variable "exclude_files" {
description = <<DESC
A list of directories or folders to ignore, e.g.
A list of source directories or folders to ignore when creating the archive, e.g.
exclude_files = ["test", "src/**/*.ts"]
DESC
type = list(string)
Expand Down

0 comments on commit b502b00

Please sign in to comment.