Skip to content

Commit ba66be9

Browse files
committed
feat: Added new resources and arguments
1 parent 0ec297a commit ba66be9

File tree

4 files changed

+196
-3
lines changed

4 files changed

+196
-3
lines changed

examples/complete-function/example.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,25 @@ module "lambda" {
2323
timeout = 60
2424
reserved_concurrent_executions = 90
2525
cloudwatch_logs_retention_in_days = 7
26+
provisioned_concurrent_executions = 2
27+
recursive_loop = "Allow"
28+
publish = true
29+
30+
######################
31+
# Lambda Function URL
32+
######################
33+
create_lambda_function_url = true
34+
authorization_type = "AWS_IAM"
35+
cors = {
36+
allow_credentials = true
37+
allow_origins = ["*"]
38+
allow_methods = ["*"]
39+
allow_headers = ["date", "keep-alive"]
40+
expose_headers = ["keep-alive", "date"]
41+
max_age = 86400
42+
}
43+
invoke_mode = "RESPONSE_STREAM"
44+
2645

2746
# -- ARNs of Triggers
2847
source_arns = [""]

examples/complete-function/outputs.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,22 @@ output "tags" {
2121
value = module.lambda.tags
2222
description = "A mapping of tags to assign to the resource."
2323
}
24+
25+
26+
output "lambda_function_url" {
27+
value = module.lambda.lambda_function_url
28+
}
29+
30+
output "lambda_function_url_id" {
31+
value = module.lambda.lambda_function_url_id
32+
}
33+
34+
output "lambda_provisioned_concurrency_config_id" {
35+
value = module.lambda.lambda_provisioned_concurrency_config_id
36+
}
37+
38+
output "lambda_recursion_config_function_name" {
39+
value = module.lambda.lambda_recursion_config_function_name
40+
}
41+
42+

main.tf

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ resource "aws_kms_key_policy" "lambda" {
229229
},
230230
{
231231
"Effect" : "Allow",
232-
"Principal" : { "Service" : "lambda.${data.aws_region.current.name}.amazonaws.com" },
232+
"Principal" : { "Service" : "lambda.${data.aws_region.current.region}.amazonaws.com" },
233233
"Action" : [
234234
"kms:Encrypt*",
235235
"kms:Decrypt*",
@@ -260,7 +260,7 @@ resource "aws_kms_key_policy" "cloudwatch" {
260260
},
261261
{
262262
"Effect" : "Allow",
263-
"Principal" : { "Service" : "logs.${data.aws_region.current.name}.amazonaws.com" },
263+
"Principal" : { "Service" : "logs.${data.aws_region.current.region}.amazonaws.com" },
264264
"Action" : [
265265
"kms:Encrypt*",
266266
"kms:Decrypt*",
@@ -317,4 +317,60 @@ resource "aws_iam_role_policy_attachment" "logs" {
317317
count = var.enable && var.create_iam_role && var.attach_cloudwatch_logs_policy ? 1 : 0
318318
role = aws_iam_role.default[0].name
319319
policy_arn = aws_iam_policy.logs[0].arn
320-
}
320+
}
321+
322+
323+
locals {
324+
create = var.create && var.putin_khuylo
325+
326+
}
327+
328+
329+
330+
331+
resource "aws_lambda_provisioned_concurrency_config" "current_version" {
332+
count = local.create && var.create_function && !var.create_layer && var.provisioned_concurrent_executions > -1 ? 1 : 0
333+
334+
region = var.region
335+
336+
function_name = aws_lambda_function.default[0].function_name
337+
qualifier = aws_lambda_function.default[0].version
338+
339+
340+
provisioned_concurrent_executions = var.provisioned_concurrent_executions
341+
}
342+
343+
344+
resource "aws_lambda_function_recursion_config" "this" {
345+
count = local.create && var.create_function && !var.create_layer && var.recursive_loop == "Allow" ? 1 : 0
346+
347+
region = var.region
348+
349+
function_name = aws_lambda_function.default[0].function_name
350+
recursive_loop = var.recursive_loop
351+
}
352+
353+
resource "aws_lambda_function_url" "this" {
354+
count = local.create && var.create_function && !var.create_layer && var.create_lambda_function_url ? 1 : 0
355+
356+
region = var.region
357+
function_name = aws_lambda_function.default[0].function_name
358+
359+
qualifier = var.create_unqualified_alias_lambda_function_url ? null : aws_lambda_function.default[0].version
360+
361+
authorization_type = var.authorization_type # e.g., "NONE" or "AWS_IAM"
362+
invoke_mode = var.invoke_mode # e.g., "BUFFERED" or "RESPONSE_STREAM"
363+
364+
dynamic "cors" {
365+
for_each = length(keys(var.cors)) == 0 ? [] : [var.cors]
366+
367+
content {
368+
allow_credentials = try(cors.value.allow_credentials, null)
369+
allow_headers = try(cors.value.allow_headers, null)
370+
allow_methods = try(cors.value.allow_methods, null)
371+
allow_origins = try(cors.value.allow_origins, null)
372+
expose_headers = try(cors.value.expose_headers, null)
373+
max_age = try(cors.value.max_age, null)
374+
}
375+
}
376+
}

variables.tf

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,3 +440,102 @@ variable "aws_iam_policy_path" {
440440
default = "/"
441441
description = "IAM policy path default value"
442442
}
443+
444+
##--------------------------------------------------------------------------------
445+
446+
variable "region" {
447+
description = "Region where the resource(s) will be managed. Defaults to the region set in the provider configuration"
448+
type = string
449+
default = null
450+
}
451+
452+
variable "create_function" {
453+
description = "Controls whether Lambda Function resource should be created"
454+
type = bool
455+
default = true
456+
}
457+
458+
variable "create_layer" {
459+
description = "Controls whether Lambda Layer resource should be created"
460+
type = bool
461+
default = false
462+
}
463+
464+
variable "create_current_version_async_event_config" {
465+
description = "Whether to allow async event configuration on current version of Lambda Function (this will revoke permissions from previous version because Terraform manages only current resources)"
466+
type = bool
467+
default = true
468+
}
469+
470+
variable "create_unqualified_alias_async_event_config" {
471+
description = "Whether to allow async event configuration on unqualified alias pointing to $LATEST version"
472+
type = bool
473+
default = true
474+
}
475+
476+
variable "create" {
477+
description = "Controls whether resources should be created"
478+
type = bool
479+
default = true
480+
}
481+
482+
variable "putin_khuylo" {
483+
description = "Do you agree that Putin doesn't respect Ukrainian sovereignty and territorial integrity? More info: https://en.wikipedia.org/wiki/Putin_khuylo!"
484+
type = bool
485+
default = true
486+
}
487+
488+
##########################
489+
# Provisioned Concurrency
490+
##########################
491+
492+
variable "provisioned_concurrent_executions" {
493+
description = "Amount of capacity to allocate. Set to 1 or greater to enable, or set to 0 to disable provisioned concurrency."
494+
type = number
495+
default = -1
496+
}
497+
498+
############################################
499+
# Lambda Recursive Loop Settings
500+
############################################
501+
502+
variable "recursive_loop" {
503+
description = "Lambda function recursion configuration. Valid values are Allow or Terminate."
504+
type = string
505+
default = null
506+
}
507+
508+
variable "create_lambda_function_url" {
509+
description = "Controls whether the Lambda Function URL resource should be created"
510+
type = bool
511+
default = false
512+
}
513+
514+
###############
515+
# Function URL
516+
###############
517+
518+
variable "create_unqualified_alias_lambda_function_url" {
519+
description = "Whether to use unqualified alias pointing to $LATEST version in Lambda Function URL"
520+
type = bool
521+
default = true
522+
}
523+
524+
variable "authorization_type" {
525+
description = "The type of authentication that the Lambda Function URL uses. Set to 'AWS_IAM' to restrict access to authenticated IAM users only. Set to 'NONE' to bypass IAM authentication and create a public endpoint."
526+
type = string
527+
default = "NONE"
528+
}
529+
530+
variable "cors" {
531+
description = "CORS settings to be used by the Lambda Function URL"
532+
type = any
533+
default = {}
534+
}
535+
536+
variable "invoke_mode" {
537+
description = "Invoke mode of the Lambda Function URL. Valid values are BUFFERED (default) and RESPONSE_STREAM."
538+
type = string
539+
default = null
540+
}
541+

0 commit comments

Comments
 (0)