Skip to content

Commit 83e12bc

Browse files
author
Eduardo Lopez
authored
[feature]: lambda vpc_config and memory_size (#301)
1 parent 9df4395 commit 83e12bc

File tree

3 files changed

+98
-30
lines changed

3 files changed

+98
-30
lines changed

aws-lambda-function/README.md

+49-30
Original file line numberDiff line numberDiff line change
@@ -24,49 +24,68 @@ module lambda {
2424

2525
| Name | Version |
2626
|------|---------|
27-
| aws | < 3.0.0 |
27+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | < 3.0.0 |
2828

2929
## Providers
3030

3131
| Name | Version |
3232
|------|---------|
33-
| aws | < 3.0.0 |
33+
| <a name="provider_aws"></a> [aws](#provider\_aws) | < 3.0.0 |
34+
35+
## Modules
36+
37+
No modules.
38+
39+
## Resources
40+
41+
| Name | Type |
42+
|------|------|
43+
| [aws_cloudwatch_log_group.log](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_log_group) | resource |
44+
| [aws_iam_policy.lambda_logging](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
45+
| [aws_iam_role.role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
46+
| [aws_iam_role_policy_attachment.lambda_logs](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
47+
| [aws_lambda_function.lambda](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_function) | resource |
48+
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
49+
| [aws_iam_policy_document.lambda_logging_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
50+
| [aws_iam_policy_document.lambda_role_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
51+
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
3452

3553
## Inputs
3654

3755
| Name | Description | Type | Default | Required |
3856
|------|-------------|------|---------|:--------:|
39-
| at\_edge | 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. | `bool` | `false` | no |
40-
| env | Env for tagging and naming. See [doc](../README.md#consistent-tagging) | `string` | n/a | yes |
41-
| environment | Map of environment variables. | `map(string)` | `{}` | no |
42-
| filename | n/a | `string` | `null` | no |
43-
| function\_description | Description for lambda function. | `string` | `""` | no |
44-
| function\_name | If not set, function use default naming convention of $project-$env-$service. See local.name in main.tf | `string` | `null` | no |
45-
| handler | Name of the lambda handler. | `string` | n/a | yes |
46-
| kms\_key\_arn | KMS key used to encrypt environment variables. | `string` | `null` | no |
47-
| lambda\_role\_path | The path to the IAM role for lambda. | `string` | `null` | no |
48-
| log\_retention\_in\_days | n/a | `number` | `null` | no |
49-
| owner | Owner for tagging and naming. See [doc](../README.md#consistent-tagging) | `string` | n/a | yes |
50-
| project | Project for tagging and naming. See [doc](../README.md#consistent-tagging) | `string` | n/a | yes |
51-
| publish\_lambda | Whether to publish creation/change as new lambda function version. | `bool` | `false` | no |
52-
| reserved\_concurrent\_executions | Set reserved\_concurrent\_executions for this function. See [docs](https://docs.aws.amazon.com/lambda/latest/dg/configuration-concurrency.html). | `number` | `-1` | no |
53-
| runtime | Lambda language runtime. | `string` | n/a | yes |
54-
| service | Service for tagging and naming. See [doc](../README.md#consistent-tagging) | `string` | n/a | yes |
55-
| source\_code\_hash | n/a | `string` | `null` | no |
56-
| source\_s3\_bucket | Bucket holding lambda source code. | `string` | `null` | no |
57-
| source\_s3\_key | Key identifying location of code. | `string` | `null` | no |
58-
| timeout | Execution timeout for the lambda. | `number` | `null` | no |
57+
| <a name="input_at_edge"></a> [at\_edge](#input\_at\_edge) | 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. | `bool` | `false` | no |
58+
| <a name="input_env"></a> [env](#input\_env) | Env for tagging and naming. See [doc](../README.md#consistent-tagging) | `string` | n/a | yes |
59+
| <a name="input_environment"></a> [environment](#input\_environment) | Map of environment variables. | `map(string)` | `{}` | no |
60+
| <a name="input_filename"></a> [filename](#input\_filename) | n/a | `string` | `null` | no |
61+
| <a name="input_function_description"></a> [function\_description](#input\_function\_description) | Description for lambda function. | `string` | `""` | no |
62+
| <a name="input_function_name"></a> [function\_name](#input\_function\_name) | If not set, function use default naming convention of $project-$env-$service. See local.name in main.tf | `string` | `null` | no |
63+
| <a name="input_handler"></a> [handler](#input\_handler) | Name of the lambda handler. | `string` | n/a | yes |
64+
| <a name="input_kms_key_arn"></a> [kms\_key\_arn](#input\_kms\_key\_arn) | KMS key used to encrypt environment variables. | `string` | `null` | no |
65+
| <a name="input_lambda_role_path"></a> [lambda\_role\_path](#input\_lambda\_role\_path) | The path to the IAM role for lambda. | `string` | `null` | no |
66+
| <a name="input_log_retention_in_days"></a> [log\_retention\_in\_days](#input\_log\_retention\_in\_days) | n/a | `number` | `null` | no |
67+
| <a name="input_memory_size"></a> [memory\_size](#input\_memory\_size) | Amount of memory to allocate to the lambda | `number` | `128` | no |
68+
| <a name="input_owner"></a> [owner](#input\_owner) | Owner for tagging and naming. See [doc](../README.md#consistent-tagging) | `string` | n/a | yes |
69+
| <a name="input_project"></a> [project](#input\_project) | Project for tagging and naming. See [doc](../README.md#consistent-tagging) | `string` | n/a | yes |
70+
| <a name="input_publish_lambda"></a> [publish\_lambda](#input\_publish\_lambda) | Whether to publish creation/change as new lambda function version. | `bool` | `false` | no |
71+
| <a name="input_reserved_concurrent_executions"></a> [reserved\_concurrent\_executions](#input\_reserved\_concurrent\_executions) | Set reserved\_concurrent\_executions for this function. See [docs](https://docs.aws.amazon.com/lambda/latest/dg/configuration-concurrency.html). | `number` | `-1` | no |
72+
| <a name="input_runtime"></a> [runtime](#input\_runtime) | Lambda language runtime. | `string` | n/a | yes |
73+
| <a name="input_service"></a> [service](#input\_service) | Service for tagging and naming. See [doc](../README.md#consistent-tagging) | `string` | n/a | yes |
74+
| <a name="input_source_code_hash"></a> [source\_code\_hash](#input\_source\_code\_hash) | n/a | `string` | `null` | no |
75+
| <a name="input_source_s3_bucket"></a> [source\_s3\_bucket](#input\_source\_s3\_bucket) | Bucket holding lambda source code. | `string` | `null` | no |
76+
| <a name="input_source_s3_key"></a> [source\_s3\_key](#input\_source\_s3\_key) | Key identifying location of code. | `string` | `null` | no |
77+
| <a name="input_timeout"></a> [timeout](#input\_timeout) | Execution timeout for the lambda. | `number` | `null` | no |
78+
| <a name="input_vpc_config"></a> [vpc\_config](#input\_vpc\_config) | The lambda's vpc configuration | <pre>object({<br> subnet_ids = list(string),<br> security_group_ids = list(string)<br> })</pre> | `null` | no |
5979

6080
## Outputs
6181

6282
| Name | Description |
6383
|------|-------------|
64-
| arn | n/a |
65-
| function\_name | n/a |
66-
| invoke\_arn | n/a |
67-
| log\_group\_name | n/a |
68-
| qualified\_arn | If the lambda function is published, the qualified\_arn points at the latest version number. |
69-
| role\_id | n/a |
70-
| role\_name | n/a |
71-
84+
| <a name="output_arn"></a> [arn](#output\_arn) | n/a |
85+
| <a name="output_function_name"></a> [function\_name](#output\_function\_name) | n/a |
86+
| <a name="output_invoke_arn"></a> [invoke\_arn](#output\_invoke\_arn) | n/a |
87+
| <a name="output_log_group_name"></a> [log\_group\_name](#output\_log\_group\_name) | n/a |
88+
| <a name="output_qualified_arn"></a> [qualified\_arn](#output\_qualified\_arn) | If the lambda function is published, the qualified\_arn points at the latest version number. |
89+
| <a name="output_role_id"></a> [role\_id](#output\_role\_id) | n/a |
90+
| <a name="output_role_name"></a> [role\_name](#output\_role\_name) | n/a |
7291
<!-- END -->

aws-lambda-function/main.tf

+33
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ resource "aws_lambda_function" "lambda" {
3939
}
4040
}
4141

42+
dynamic "vpc_config" {
43+
for_each = var.vpc_config == null ? [] : [0]
44+
45+
content {
46+
subnet_ids = var.vpc_config.subnet_ids
47+
security_group_ids = var.vpc_config.security_group_ids
48+
}
49+
}
50+
51+
memory_size = var.memory_size
52+
4253
tags = local.tags
4354
}
4455

@@ -110,3 +121,25 @@ resource "aws_iam_role_policy_attachment" "lambda_logs" {
110121
role = aws_iam_role.role.name
111122
policy_arn = aws_iam_policy.lambda_logging.arn
112123
}
124+
125+
// Execution role basic permissions
126+
data "aws_iam_policy_document" "role" {
127+
statement {
128+
sid = "ec2"
129+
effect = "Allow"
130+
actions = [
131+
"ec2:CreateNetworkInterface",
132+
"ec2:DescribeNetworkInterfaces",
133+
"ec2:DeleteNetworkInterface",
134+
]
135+
136+
resources = [
137+
"*",
138+
]
139+
}
140+
}
141+
142+
resource "aws_iam_role_policy" "role" {
143+
role = aws_iam_role.role.name
144+
policy = data.aws_iam_policy_document.role.json
145+
}

aws-lambda-function/variables.tf

+16
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,19 @@ variable "reserved_concurrent_executions" {
108108
description = "Set reserved_concurrent_executions for this function. See [docs](https://docs.aws.amazon.com/lambda/latest/dg/configuration-concurrency.html)."
109109
default = -1 // aws default
110110
}
111+
112+
variable "vpc_config" {
113+
type = object({
114+
subnet_ids = list(string),
115+
security_group_ids = list(string)
116+
})
117+
118+
description = "The lambda's vpc configuration"
119+
default = null
120+
}
121+
122+
variable "memory_size" {
123+
type = number
124+
description = "Amount of memory to allocate to the lambda"
125+
default = 128
126+
}

0 commit comments

Comments
 (0)