Skip to content

Commit b5fcd02

Browse files
committed
feat(ami-updater): add s3 support for lambda deployment
- add s3 bucket, key, and version variables for lambda deployment - make lambda zip path configurable via variable - add support for additional lambda tags - update lambda resource to handle both local and s3 deployments
1 parent def9515 commit b5fcd02

File tree

2 files changed

+44
-11
lines changed

2 files changed

+44
-11
lines changed

modules/ami-updater/main.tf

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
locals {
2-
lambda_zip = "${path.module}/../../lambdas/functions/ami-updater/dist/ami-updater.zip"
2+
lambda_zip = var.lambda_zip == null ? "${path.module}/../../lambdas/functions/ami-updater/dist/ami-updater.zip" : var.lambda_zip
33
role_path = var.role_path == null ? "/${var.prefix}/" : var.role_path
44
tags = merge(
55
{
@@ -11,16 +11,19 @@ locals {
1111
}
1212

1313
resource "aws_lambda_function" "ami_updater" {
14-
filename = local.lambda_zip
15-
source_code_hash = filebase64sha256(local.lambda_zip)
16-
function_name = "${var.prefix}-ami-updater"
17-
role = aws_iam_role.ami_updater.arn
18-
handler = "index.handler"
19-
runtime = var.lambda_runtime
20-
timeout = var.lambda_timeout
21-
memory_size = var.lambda_memory_size
22-
architectures = [var.lambda_architecture]
23-
tags = local.tags
14+
s3_bucket = var.lambda_s3_bucket != null ? var.lambda_s3_bucket : null
15+
s3_key = var.lambda_s3_key != null ? var.lambda_s3_key : null
16+
s3_object_version = var.lambda_s3_object_version != null ? var.lambda_s3_object_version : null
17+
filename = var.lambda_s3_bucket == null ? local.lambda_zip : null
18+
source_code_hash = var.lambda_s3_bucket == null ? filebase64sha256(local.lambda_zip) : null
19+
function_name = "${var.prefix}-ami-updater"
20+
role = aws_iam_role.ami_updater.arn
21+
handler = "index.handler"
22+
runtime = var.lambda_runtime
23+
timeout = var.lambda_timeout
24+
memory_size = var.lambda_memory_size
25+
architectures = [var.lambda_architecture]
26+
tags = merge(local.tags, var.lambda_tags)
2427

2528
environment {
2629
variables = {

modules/ami-updater/variables.tf

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,33 @@ variable "config" {
130130
})
131131
})
132132
}
133+
134+
variable "lambda_zip" {
135+
description = "Path to Lambda zip file, will be used when S3 bucket is not set"
136+
type = string
137+
default = null
138+
}
139+
140+
variable "lambda_s3_bucket" {
141+
description = "S3 bucket from which to specify lambda functions source code"
142+
type = string
143+
default = null
144+
}
145+
146+
variable "lambda_s3_key" {
147+
description = "S3 key from which to specify lambda function source code"
148+
type = string
149+
default = null
150+
}
151+
152+
variable "lambda_s3_object_version" {
153+
description = "S3 object version from which to specify lambda function source code"
154+
type = string
155+
default = null
156+
}
157+
158+
variable "lambda_tags" {
159+
description = "Additional tags to apply to the Lambda function"
160+
type = map(string)
161+
default = {}
162+
}

0 commit comments

Comments
 (0)