Skip to content

add var for s3 upload #16

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
16 changes: 8 additions & 8 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ locals {

lambda_role_arn = var.is_create_lambda_role ? aws_iam_role.this[0].arn : var.lambda_role_arn

file_name = var.is_edge ? null : data.archive_file.this.output_path
bucket_name = var.is_edge ? var.is_create_lambda_bucket ? module.s3[0].bucket_name : var.bucket_name : null
object_key = var.is_edge ? aws_s3_object.this[0].id : null
object_version_id = var.is_edge ? aws_s3_object.this[0].version_id : null
file_name = var.is_s3_upload ? null : data.archive_file.this.output_path
bucket_name = var.is_s3_upload ? var.is_create_lambda_bucket ? module.s3[0].bucket_name : var.bucket_name : null
object_key = var.is_s3_upload ? aws_s3_object.this[0].id : null
object_version_id = var.is_s3_upload ? aws_s3_object.this[0].version_id : null

tags = merge(
{
Expand All @@ -23,7 +23,7 @@ locals {
locals {
raise_is_lambda_role_arn_empty = var.is_create_lambda_role == false && var.lambda_role_arn == "" ? file("Variable `lambda_role_arn` is required when `is_create_lambda_role` is false") : "pass"

raise_bucket_name_empty = var.is_edge && var.is_create_lambda_bucket == false && length(var.bucket_name) == 0 ? file("Variable `bucket_name` is required when `is_create_lambda_bucket` is false") : "pass"
raise_bucket_name_empty = var.is_s3_upload && var.is_create_lambda_bucket == false && length(var.bucket_name) == 0 ? file("Variable `bucket_name` is required when `is_create_lambda_bucket` is false") : "pass"
raise_local_file_dir_empty = length(var.compressed_local_file_dir) == 0 ? file("Variable `compressed_local_file_dir` is required") : "pass"
raise_file_globs_empty = length(var.file_globs) == 0 ? file("Variable `file_globs` is required") : "pass"
}
Expand Down Expand Up @@ -64,7 +64,7 @@ data "archive_file" "this" {
/* S3 */
/* -------------------------------------------------------------------------- */
module "s3" {
count = var.is_edge && var.is_create_lambda_bucket ? 1 : 0
count = var.is_s3_upload && var.is_create_lambda_bucket ? 1 : 0

source = "oozou/s3/aws"
version = "1.1.3"
Expand All @@ -82,7 +82,7 @@ module "s3" {
}

resource "aws_s3_object" "this" {
count = var.is_edge && var.is_create_lambda_bucket ? 1 : 0
count = var.is_s3_upload && var.is_create_lambda_bucket ? 1 : 0

bucket = element(module.s3[*].bucket_name, 0)
key = format("%s.zip", local.name)
Expand Down Expand Up @@ -270,7 +270,7 @@ resource "aws_lambda_function" "this" {
reserved_concurrent_executions = var.reserved_concurrent_executions

# Code Env
publish = true # Force public new version
publish = var.is_publish # Force public new version
runtime = var.runtime
handler = var.handler

Expand Down
13 changes: 13 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,19 @@ variable "is_edge" {
default = false
}

variable "is_s3_upload" {
description = "Whether upload the source code from s3 bucket"
type = bool
default = false
}

variable "is_publish" {
description = "Whether publish the lambda function"
type = bool
default = true
}


variable "timeout" {
description = "(Optional) Amount of time your Lambda Function has to run in seconds. Defaults to 3."
type = number
Expand Down