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(lambda): Added package_path and package_s3 inputs #104

Merged
merged 4 commits into from
Mar 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
27 changes: 27 additions & 0 deletions lambda/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,32 @@ Creates an AWS Lambda function

* `file_exclude_patterns` (`list(string)`, default: `[]`)

**Deprecated. Use the `zip` module and `package_path` input instead.**

Source code file exclusion patterns in case some unnecessary files are matched by `file_paths`.


* `file_patterns` (`list(string)`, default: `["**"]`)

**Deprecated. Use the `zip` module and `package_path` input instead.**

Source code file path patterns to narrow `files_dir` contents.


* `files` (`map(string)`, default: `null`)

**Deprecated. Use the `zip` module and `package_path` input instead.**

Source code map. Either `files` or `files_dir` has to be specified


* `files_dir` (`string`, default: `null`)

**Deprecated. Use the `zip` module and `package_path` input instead.**

Source code directory path. Either `files` or `files_dir` has to be specified


* `handler` (`string`, default: `"index.handler"`)

Path to the event handler
Expand All @@ -57,6 +69,21 @@ Creates an AWS Lambda function

Lambda name

* `package_path` (`string`, default: `null`)

Path to the zip that contains the Lambda's source. Either `package_path` or `package_s3` is required.

* `package_s3` (`object({
bucket = string
key = string
})`, default: `null`)

S3 zip object that contains the Lambda's source. Either `package_path` or `package_s3` is required.

* `package_s3_version` (`string`, default: `null`)

Version number of the S3 object to use

* `policy_arns` (`map(string)`, default: `{}`)

Additional policy ARNs to attach to the Lambda role
Expand Down
27 changes: 27 additions & 0 deletions lambda/layer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,51 @@ Creates an AWS Lambda Layer that can be attached to a AWS Lambda Function

* `file_exclude_patterns` (`list(string)`, default: `[]`)

**Deprecated. Use the `zip` module and `package_path` input instead.**

Source code file exclusion patterns in case some unnecessary files are matched by `file_paths`.


* `file_patterns` (`list(string)`, default: `["**"]`)

**Deprecated. Use the `zip` module and `package_path` input instead.**

Source code file path patterns to narrow `files_dir` contents.


* `files` (`map(string)`, default: `null`)

**Deprecated. Use the `zip` module and `package_path` input instead.**

Source code map. Either `files` or `files_dir` has to be specified


* `files_dir` (`string`, default: `null`)

**Deprecated. Use the `zip` module and `package_path` input instead.**

Source code directory path. Either `files` or `files_dir` has to be specified


* `name` (`string`, required)

Lambda layer name

* `package_path` (`string`, default: `null`)

Path to the zip that contains the Lambda layer's source. Either `package_path`, `package_s3` or `image` is required.

* `package_s3` (`object({
bucket = string
key = string
})`, default: `null`)

S3 zip object that contains the Lambda layer's source. Either `package_path` or `package_s3` is required.

* `package_s3_version` (`string`, default: `null`)

Version number of the S3 object to use

* `runtimes` (`list(string)`, default: `["nodejs12.x"]`)

[Runtimes](https://docs.aws.amazon.com/lambda/latest/dg/API_CreateFunction.html#SSS-CreateFunction-request-Runtime) compatible with this lambda layer
Expand Down
3 changes: 0 additions & 3 deletions lambda/layer/example/main.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
provider "aws" {
region = "eu-west-1" # Ireland

# https://github.com/hashicorp/terraform-provider-aws/issues/15952
version = "3.12.0"
}

module "lambda_layer" {
Expand Down
12 changes: 10 additions & 2 deletions lambda/layer/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
locals {
create_package = var.create && (var.files != null || var.files_dir != null)
}

module "package" {
source = "./../../zip"
create = var.create
create = local.create_package

files = var.files
directory = var.files_dir
Expand All @@ -14,8 +18,12 @@ resource "aws_lambda_layer_version" "layer" {
count = var.create ? 1 : 0

layer_name = var.name
filename = module.package.output_path
compatible_runtimes = var.runtimes

filename = local.create_package ? module.package.output_path : var.package_path
s3_bucket = var.package_s3 != null ? var.package_s3.bucket : null
s3_key = var.package_s3 != null ? var.package_s3.key : null
s3_object_version = var.package_s3_version
}

locals {
Expand Down
63 changes: 52 additions & 11 deletions lambda/layer/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,68 @@ variable "runtimes" {
default = ["nodejs12.x"]
}

variable "files" {
description = "Source code map. Either `files` or `files_dir` has to be specified"
type = map(string)
variable "package_path" {
description = "Path to the zip that contains the Lambda layer's source. Either `package_path`, `package_s3` or `image` is required."
type = string
default = null
}

variable "files_dir" {
description = "Source code directory path. Either `files` or `files_dir` has to be specified"
variable "package_s3" {
description = "S3 zip object that contains the Lambda layer's source. Either `package_path` or `package_s3` is required."
type = object({
bucket = string
key = string
})
default = null
}

variable "package_s3_version" {
description = "Version number of the S3 object to use"
type = string
default = null
}

variable "files" {
description = <<EOT
**Deprecated. Use the `zip` module and `package_path` input instead.**

Source code map. Either `files` or `files_dir` has to be specified
EOT

type = map(string)
default = null
}

variable "files_dir" {
description = <<EOT
**Deprecated. Use the `zip` module and `package_path` input instead.**

Source code directory path. Either `files` or `files_dir` has to be specified
EOT

type = string
default = null
}

variable "file_patterns" {
description = "Source code file path patterns to narrow `files_dir` contents."
type = list(string)
default = ["**"]
description = <<EOT
**Deprecated. Use the `zip` module and `package_path` input instead.**

Source code file path patterns to narrow `files_dir` contents.
EOT

type = list(string)
default = ["**"]
}

variable "file_exclude_patterns" {
description = "Source code file exclusion patterns in case some unnecessary files are matched by `file_paths`."
type = list(string)
default = []
description = <<EOT
**Deprecated. Use the `zip` module and `package_path` input instead.**

Source code file exclusion patterns in case some unnecessary files are matched by `file_paths`.
EOT

type = list(string)
default = []
}

27 changes: 18 additions & 9 deletions lambda/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
locals {
create_package = var.create && (var.files != null || var.files_dir != null)
}

module "package" {
source = "./../zip"
create = var.create
create = local.create_package

files = var.files
directory = var.files_dir
Expand Down Expand Up @@ -72,14 +76,19 @@ resource "aws_lambda_function" "lambda" {
]

function_name = var.name
filename = module.package.output_path
layers = var.layer_qualified_arns
handler = var.handler
runtime = var.runtime
publish = true
timeout = var.timeout
memory_size = var.memory_size
role = aws_iam_role.lambda[0].arn

filename = local.create_package ? module.package.output_path : var.package_path
s3_bucket = var.package_s3 != null ? var.package_s3.bucket : null
s3_key = var.package_s3 != null ? var.package_s3.key : null
s3_object_version = var.package_s3_version

layers = var.layer_qualified_arns
handler = var.handler
runtime = var.runtime
publish = true
timeout = var.timeout
memory_size = var.memory_size
role = aws_iam_role.lambda[0].arn

# AWS provider requires at least one environment variable in the environment block,
# so just don't create the block at all if var.environment_variables is empty
Expand Down
63 changes: 52 additions & 11 deletions lambda/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,69 @@ variable "name" {
type = string
}

variable "files" {
description = "Source code map. Either `files` or `files_dir` has to be specified"
type = map(string)
variable "package_path" {
description = "Path to the zip that contains the Lambda's source. Either `package_path` or `package_s3` is required."
type = string
default = null
}

variable "files_dir" {
description = "Source code directory path. Either `files` or `files_dir` has to be specified"
variable "package_s3" {
description = "S3 zip object that contains the Lambda's source. Either `package_path` or `package_s3` is required."
type = object({
bucket = string
key = string
})
default = null
}

variable "package_s3_version" {
description = "Version number of the S3 object to use"
type = string
default = null
}

variable "files" {
description = <<EOT
**Deprecated. Use the `zip` module and `package_path` input instead.**

Source code map. Either `files` or `files_dir` has to be specified
EOT

type = map(string)
default = null
}

variable "files_dir" {
description = <<EOT
**Deprecated. Use the `zip` module and `package_path` input instead.**

Source code directory path. Either `files` or `files_dir` has to be specified
EOT

type = string
default = null
}

variable "file_patterns" {
description = "Source code file path patterns to narrow `files_dir` contents."
type = list(string)
default = ["**"]
description = <<EOT
**Deprecated. Use the `zip` module and `package_path` input instead.**

Source code file path patterns to narrow `files_dir` contents.
EOT

type = list(string)
default = ["**"]
}

variable "file_exclude_patterns" {
description = "Source code file exclusion patterns in case some unnecessary files are matched by `file_paths`."
type = list(string)
default = []
description = <<EOT
**Deprecated. Use the `zip` module and `package_path` input instead.**

Source code file exclusion patterns in case some unnecessary files are matched by `file_paths`.
EOT

type = list(string)
default = []
}

variable "runtime" {
Expand Down