Skip to content

Commit 2d92236

Browse files
authored
feat: Added configuration options to replace security groups on destroy of Lambda function (#422)
1 parent f0f16f1 commit 2d92236

File tree

5 files changed

+39
-21
lines changed

5 files changed

+39
-21
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ Q4: What does this error mean - `"We currently do not support adding policies fo
659659
| Name | Version |
660660
|------|---------|
661661
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
662-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.44 |
662+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.54 |
663663
| <a name="requirement_external"></a> [external](#requirement\_external) | >= 1.0 |
664664
| <a name="requirement_local"></a> [local](#requirement\_local) | >= 1.0 |
665665
| <a name="requirement_null"></a> [null](#requirement\_null) | >= 2.0 |
@@ -668,7 +668,7 @@ Q4: What does this error mean - `"We currently do not support adding policies fo
668668

669669
| Name | Version |
670670
|------|---------|
671-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.44 |
671+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.54 |
672672
| <a name="provider_external"></a> [external](#provider\_external) | >= 1.0 |
673673
| <a name="provider_local"></a> [local](#provider\_local) | >= 1.0 |
674674
| <a name="provider_null"></a> [null](#provider\_null) | >= 2.0 |
@@ -816,6 +816,8 @@ No modules.
816816
| <a name="input_publish"></a> [publish](#input\_publish) | Whether to publish creation/change as new Lambda Function Version. | `bool` | `false` | no |
817817
| <a name="input_putin_khuylo"></a> [putin\_khuylo](#input\_putin\_khuylo) | Do you agree that Putin doesn't respect Ukrainian sovereignty and territorial integrity? More info: https://en.wikipedia.org/wiki/Putin_khuylo! | `bool` | `true` | no |
818818
| <a name="input_recreate_missing_package"></a> [recreate\_missing\_package](#input\_recreate\_missing\_package) | Whether to recreate missing Lambda package if it is missing locally or not | `bool` | `true` | no |
819+
| <a name="input_replace_security_groups_on_destroy"></a> [replace\_security\_groups\_on\_destroy](#input\_replace\_security\_groups\_on\_destroy) | (Optional) When true, all security groups defined in vpc\_security\_group\_ids will be replaced with the default security group after the function is destroyed. Set the replacement\_security\_group\_ids variable to use a custom list of security groups for replacement instead. | `bool` | `null` | no |
820+
| <a name="input_replacement_security_group_ids"></a> [replacement\_security\_group\_ids](#input\_replacement\_security\_group\_ids) | (Optional) List of security group IDs to assign to orphaned Lambda function network interfaces upon destruction. replace\_security\_groups\_on\_destroy must be set to true to use this attribute. | `list(string)` | `[]` | no |
819821
| <a name="input_reserved_concurrent_executions"></a> [reserved\_concurrent\_executions](#input\_reserved\_concurrent\_executions) | The amount of reserved concurrent executions for this Lambda Function. A value of 0 disables Lambda Function from being triggered and -1 removes any concurrency limitations. Defaults to Unreserved Concurrency Limits -1. | `number` | `-1` | no |
820822
| <a name="input_role_description"></a> [role\_description](#input\_role\_description) | Description of IAM role to use for Lambda Function | `string` | `null` | no |
821823
| <a name="input_role_force_detach_policies"></a> [role\_force\_detach\_policies](#input\_role\_force\_detach\_policies) | Specifies to force detaching any policies the IAM role has before destroying it. | `bool` | `true` | no |

examples/with-vpc/main.tf

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ module "lambda_function_in_vpc" {
2323

2424
source_path = "${path.module}/../fixtures/python3.8-app1"
2525

26-
vpc_subnet_ids = module.vpc.intra_subnets
27-
vpc_security_group_ids = [module.vpc.default_security_group_id]
28-
attach_network_policy = true
26+
vpc_subnet_ids = module.vpc.intra_subnets
27+
vpc_security_group_ids = [module.vpc.default_security_group_id]
28+
attach_network_policy = true
29+
replace_security_groups_on_destroy = true
30+
replacement_security_group_ids = [module.vpc.default_security_group_id]
2931
}
3032

3133
module "vpc" {

main.tf

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,23 @@ locals {
2424
resource "aws_lambda_function" "this" {
2525
count = local.create && var.create_function && !var.create_layer ? 1 : 0
2626

27-
function_name = var.function_name
28-
description = var.description
29-
role = var.create_role ? aws_iam_role.lambda[0].arn : var.lambda_role
30-
handler = var.package_type != "Zip" ? null : var.handler
31-
memory_size = var.memory_size
32-
reserved_concurrent_executions = var.reserved_concurrent_executions
33-
runtime = var.package_type != "Zip" ? null : var.runtime
34-
layers = var.layers
35-
timeout = var.lambda_at_edge ? min(var.timeout, 30) : var.timeout
36-
publish = (var.lambda_at_edge || var.snap_start) ? true : var.publish
37-
kms_key_arn = var.kms_key_arn
38-
image_uri = var.image_uri
39-
package_type = var.package_type
40-
architectures = var.architectures
41-
code_signing_config_arn = var.code_signing_config_arn
27+
function_name = var.function_name
28+
description = var.description
29+
role = var.create_role ? aws_iam_role.lambda[0].arn : var.lambda_role
30+
handler = var.package_type != "Zip" ? null : var.handler
31+
memory_size = var.memory_size
32+
reserved_concurrent_executions = var.reserved_concurrent_executions
33+
runtime = var.package_type != "Zip" ? null : var.runtime
34+
layers = var.layers
35+
timeout = var.lambda_at_edge ? min(var.timeout, 30) : var.timeout
36+
publish = (var.lambda_at_edge || var.snap_start) ? true : var.publish
37+
kms_key_arn = var.kms_key_arn
38+
image_uri = var.image_uri
39+
package_type = var.package_type
40+
architectures = var.architectures
41+
code_signing_config_arn = var.code_signing_config_arn
42+
replace_security_groups_on_destroy = var.replace_security_groups_on_destroy
43+
replacement_security_group_ids = var.replacement_security_group_ids
4244

4345
/* ephemeral_storage is not supported in gov-cloud region, so it should be set to `null` */
4446
dynamic "ephemeral_storage" {

variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,18 @@ variable "snap_start" {
223223
default = false
224224
}
225225

226+
variable "replace_security_groups_on_destroy" {
227+
description = "(Optional) When true, all security groups defined in vpc_security_group_ids will be replaced with the default security group after the function is destroyed. Set the replacement_security_group_ids variable to use a custom list of security groups for replacement instead."
228+
type = bool
229+
default = null
230+
}
231+
232+
variable "replacement_security_group_ids" {
233+
description = "(Optional) List of security group IDs to assign to orphaned Lambda function network interfaces upon destruction. replace_security_groups_on_destroy must be set to true to use this attribute."
234+
type = list(string)
235+
default = []
236+
}
237+
226238
###############
227239
# Function URL
228240
###############

versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 4.44"
7+
version = ">= 4.54"
88
}
99
external = {
1010
source = "hashicorp/external"

0 commit comments

Comments
 (0)