Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Make archiving optional #30

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ Check [examples](./examples) for non-python examples.
|------|-------------|------|:--------:|
| <a name="input_function_name"></a> [function\_name](#input\_function\_name) | A unique name for your Lambda Function. | `string` | yes |
| <a name="input_handler"></a> [handler](#input\_handler) | The function entrypoint in your code. | `string` | yes |
| <a name="input_output_path"></a> [output\_path](#input\_output\_path) | A path to which the source directory is archived before uploading to AWS. | `string` | yes |
| <a name="input_output_path"></a> [output\_path](#input\_output\_path) | 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`. | `string` | yes |
| <a name="input_runtime"></a> [runtime](#input\_runtime) | The identifier of the function's runtime. | `string` | yes |
| <a name="input_source_dir"></a> [source\_dir](#input\_source\_dir) | A path to the directory which contains source files. | `string` | yes |
| <a name="input_source_dir"></a> [source\_dir](#input\_source\_dir) | A path to the directory which contains source files to be archived. If set to `null`, then no archive file is created. | `string` | yes |
| <a name="input_allowed_services"></a> [allowed\_services](#input\_allowed\_services) | A list of AWS Services that are allowed to access this lambda. | `list(string)` | no |
| <a name="input_build_command"></a> [build\_command](#input\_build\_command) | This is the build command to execute. It can be provided as a relative path to the current working directory or as an absolute path. It is evaluated in a shell, and can use environment variables or Terraform variables. | `string` | no |
| <a name="input_build_triggers"></a> [build\_triggers](#input\_build\_triggers) | A map of values which should cause the build command to re-run. Values are meant to be interpolated references to variables or attributes of other resources. | `map(string)` | no |
Expand Down
1 change: 1 addition & 0 deletions build.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ resource "null_resource" "build" {
}

data "archive_file" "source" {
count = var.source_dir != null ? 1 : 0
type = "zip"
source_dir = var.source_dir
excludes = var.exclude_files
Expand Down
15 changes: 13 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,21 @@ resource "aws_cloudwatch_log_group" "this" {
# Lambda function
#---------------------------------------------------------------------------------------------------

locals {
lambda_filename = try(
data.archive_file.source[0].output_path,
var.output_path
)
lambda_source_code_hash = try(
data.archive_file.source[0].output_base64sha256,
filebase64sha256(var.output_path)
)
}

resource "aws_lambda_function" "this" {
filename = data.archive_file.source.output_path
filename = local.lambda_filename
role = aws_iam_role.this.arn
source_code_hash = data.archive_file.source.output_base64sha256
source_code_hash = local.lambda_source_code_hash

runtime = var.runtime
handler = var.handler
Expand Down
4 changes: 2 additions & 2 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ variable "build_triggers" {
}

variable "source_dir" {
description = "A path to the directory which contains source files."
description = "A path to the directory which contains source files to be archived. If set to `null`, then no archive file is created."
type = string
}

variable "output_path" {
description = "A path to which the source directory is archived before uploading to AWS."
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`."
type = string
}

Expand Down