-
Notifications
You must be signed in to change notification settings - Fork 25
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
[feature]: lambda vpc_config and memory_size #301
Changes from 9 commits
2b3a561
7768b6c
8e406dd
97de336
a9d1334
3d75080
51946bb
88f8fce
d19d488
149593b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ locals { | |
} | ||
|
||
|
||
resource aws_lambda_function lambda { | ||
resource "aws_lambda_function" "lambda" { | ||
s3_bucket = var.source_s3_bucket | ||
s3_key = var.source_s3_key | ||
|
||
|
@@ -31,18 +31,29 @@ resource aws_lambda_function lambda { | |
|
||
reserved_concurrent_executions = var.reserved_concurrent_executions | ||
|
||
dynamic environment { | ||
dynamic "environment" { | ||
for_each = length(var.environment) > 0 ? [0] : [] | ||
|
||
content { | ||
variables = var.environment | ||
} | ||
} | ||
|
||
dynamic "vpc_config" { | ||
for_each = var.vpc_config == null ? [] : [0] | ||
|
||
content { | ||
subnet_ids = var.vpc_config.subnet_ids | ||
security_group_ids = var.vpc_config.security_group_ids | ||
} | ||
} | ||
|
||
memory_size = var.memory_size | ||
|
||
tags = local.tags | ||
} | ||
|
||
data aws_iam_policy_document lambda_role_policy { | ||
data "aws_iam_policy_document" "lambda_role_policy" { | ||
statement { | ||
principals { | ||
type = "Service" | ||
|
@@ -55,7 +66,7 @@ data aws_iam_policy_document lambda_role_policy { | |
} | ||
} | ||
|
||
resource aws_iam_role role { | ||
resource "aws_iam_role" "role" { | ||
name = local.name | ||
path = var.lambda_role_path | ||
|
||
|
@@ -64,13 +75,13 @@ resource aws_iam_role role { | |
tags = local.tags | ||
} | ||
|
||
resource aws_cloudwatch_log_group log { | ||
resource "aws_cloudwatch_log_group" "log" { | ||
name = "/aws/lambda/${local.name}" | ||
retention_in_days = var.log_retention_in_days | ||
} | ||
|
||
data aws_region current {} | ||
data aws_caller_identity current {} | ||
data "aws_region" "current" {} | ||
data "aws_caller_identity" "current" {} | ||
|
||
# TODO scope this policy down | ||
# | ||
|
@@ -81,7 +92,7 @@ data aws_caller_identity current {} | |
# arn:aws:logs:us-west-2:123456789:log-group:/foo/bar | ||
# to match operations on the log group(like creating a new stream.) So instead we construct one | ||
# without the colon before the *, so that we can match both log groups and log streams. | ||
data aws_iam_policy_document lambda_logging_policy { | ||
data "aws_iam_policy_document" "lambda_logging_policy" { | ||
statement { | ||
effect = "Allow" | ||
actions = compact([ | ||
|
@@ -98,15 +109,37 @@ data aws_iam_policy_document lambda_logging_policy { | |
} | ||
} | ||
|
||
resource aws_iam_policy lambda_logging { | ||
resource "aws_iam_policy" "lambda_logging" { | ||
name_prefix = "${local.name}-lambda-logging" | ||
path = "/" | ||
description = "IAM policy for logging from the ${local.name} lambda." | ||
|
||
policy = data.aws_iam_policy_document.lambda_logging_policy.json | ||
} | ||
|
||
resource aws_iam_role_policy_attachment lambda_logs { | ||
resource "aws_iam_role_policy_attachment" "lambda_logs" { | ||
role = aws_iam_role.role.name | ||
policy_arn = aws_iam_policy.lambda_logging.arn | ||
} | ||
|
||
// Execution role basic permissions | ||
data "aws_iam_policy_document" "role" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
statement { | ||
sid = "ec2" | ||
effect = "Allow" | ||
actions = [ | ||
"ec2:CreateNetworkInterface", | ||
"ec2:DescribeNetworkInterfaces", | ||
"ec2:DeleteNetworkInterface", | ||
] | ||
|
||
resources = [ | ||
"*", | ||
] | ||
} | ||
} | ||
|
||
resource "aws_iam_role_policy" "role" { | ||
role = aws_iam_role.role.name | ||
policy = data.aws_iam_policy_document.role.json | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,28 @@ | ||
output arn { | ||
output "arn" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 [tflint] reported by reviewdog 🐶 |
||
value = aws_lambda_function.lambda.arn | ||
} | ||
|
||
output qualified_arn { | ||
output "qualified_arn" { | ||
description = "If the lambda function is published, the qualified_arn points at the latest version number." | ||
value = aws_lambda_function.lambda.qualified_arn | ||
} | ||
|
||
output invoke_arn { | ||
output "invoke_arn" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 [tflint] reported by reviewdog 🐶 |
||
value = aws_lambda_function.lambda.invoke_arn | ||
} | ||
|
||
output function_name { | ||
output "function_name" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 [tflint] reported by reviewdog 🐶 |
||
value = aws_lambda_function.lambda.function_name | ||
} | ||
|
||
output log_group_name { | ||
output "log_group_name" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 [tflint] reported by reviewdog 🐶 |
||
value = aws_cloudwatch_log_group.log.name | ||
} | ||
|
||
output role_name { | ||
output "role_name" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 [tflint] reported by reviewdog 🐶 |
||
value = aws_iam_role.role.name | ||
} | ||
|
||
output role_id { | ||
output "role_id" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 [tflint] reported by reviewdog 🐶 |
||
value = aws_iam_role.role.id | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,110 +1,126 @@ | ||
variable project { | ||
variable "project" { | ||
type = string | ||
description = "Project for tagging and naming. See [doc](../README.md#consistent-tagging)" | ||
} | ||
|
||
variable env { | ||
variable "env" { | ||
type = string | ||
description = "Env for tagging and naming. See [doc](../README.md#consistent-tagging)" | ||
} | ||
|
||
variable service { | ||
variable "service" { | ||
type = string | ||
description = "Service for tagging and naming. See [doc](../README.md#consistent-tagging)" | ||
} | ||
|
||
variable owner { | ||
variable "owner" { | ||
type = string | ||
description = "Owner for tagging and naming. See [doc](../README.md#consistent-tagging)" | ||
} | ||
|
||
variable source_s3_bucket { | ||
variable "source_s3_bucket" { | ||
type = string | ||
description = "Bucket holding lambda source code." | ||
default = null | ||
} | ||
|
||
variable source_s3_key { | ||
variable "source_s3_key" { | ||
type = string | ||
description = "Key identifying location of code." | ||
default = null | ||
} | ||
|
||
variable handler { | ||
variable "handler" { | ||
type = string | ||
description = "Name of the lambda handler." | ||
} | ||
|
||
variable runtime { | ||
variable "runtime" { | ||
type = string | ||
description = "Lambda language runtime." | ||
} | ||
|
||
variable timeout { | ||
variable "timeout" { | ||
type = number | ||
description = "Execution timeout for the lambda." | ||
default = null | ||
} | ||
|
||
variable environment { | ||
variable "environment" { | ||
type = map(string) | ||
description = "Map of environment variables." | ||
default = {} | ||
} | ||
|
||
variable kms_key_arn { | ||
variable "kms_key_arn" { | ||
type = string | ||
description = "KMS key used to encrypt environment variables." | ||
default = null | ||
} | ||
|
||
variable source_code_hash { | ||
variable "source_code_hash" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 [tflint] reported by reviewdog 🐶 |
||
type = string | ||
default = null | ||
} | ||
|
||
variable filename { | ||
variable "filename" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 [tflint] reported by reviewdog 🐶 |
||
type = string | ||
default = null | ||
} | ||
|
||
variable log_retention_in_days { | ||
variable "log_retention_in_days" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 [tflint] reported by reviewdog 🐶 |
||
type = number | ||
default = null | ||
} | ||
|
||
variable function_name { | ||
variable "function_name" { | ||
type = string | ||
description = "If not set, function use default naming convention of $project-$env-$service. See local.name in main.tf" | ||
default = null | ||
} | ||
|
||
variable function_description { | ||
variable "function_description" { | ||
type = string | ||
description = "Description for lambda function." | ||
default = "" | ||
} | ||
|
||
variable publish_lambda { | ||
variable "publish_lambda" { | ||
type = bool | ||
description = "Whether to publish creation/change as new lambda function version." | ||
default = false | ||
} | ||
|
||
variable lambda_role_path { | ||
variable "lambda_role_path" { | ||
type = string | ||
description = "The path to the IAM role for lambda." | ||
default = null | ||
} | ||
|
||
variable at_edge { | ||
variable "at_edge" { | ||
type = bool | ||
description = "Is this lambda going to be used with a Cloufront distribution? If you set this, you will not have control over log retention, and you cannot include environment variables." | ||
default = false | ||
} | ||
|
||
variable reserved_concurrent_executions { | ||
variable "reserved_concurrent_executions" { | ||
type = number | ||
description = "Set reserved_concurrent_executions for this function. See [docs](https://docs.aws.amazon.com/lambda/latest/dg/configuration-concurrency.html)." | ||
default = -1 // aws default | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
variable "vpc_config" { | ||
type = object({ | ||
subnet_ids = list(string), | ||
security_group_ids = list(string) | ||
}) | ||
|
||
description = "The lambda's vpc configuration" | ||
default = null | ||
} | ||
|
||
variable "memory_size" { | ||
type = number | ||
description = "Amount of memory to allocate to the lambda" | ||
default = 128 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Single line comments should begin with #