Skip to content

Commit 8dc0169

Browse files
committed
feat: support snap_start configuration by function
Includes tests
1 parent 07bb0dd commit 8dc0169

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

main.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ resource "aws_lambda_function" "lambda_application" {
101101
}
102102
}
103103

104+
dynamic "snap_start" {
105+
for_each = each.value.enable_snap_start ? [true] : []
106+
content {
107+
apply_on = "PublishedVersions"
108+
}
109+
}
110+
104111
tags = local.tags
105112
}
106113

tests/main.tftest.hcl

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ variables {
1616
description = "API handler function"
1717
}
1818
worker = {
19-
handler = "worker/index.handler"
20-
enable_vpc = true
21-
description = "Background worker function"
22-
function_memory = "512"
23-
function_timeout = 60
24-
s3_key = "worker.zip"
19+
handler = "worker/index.handler"
20+
enable_vpc = true
21+
description = "Background worker function"
22+
function_memory = "512"
23+
function_timeout = 60
24+
s3_key = "worker.zip"
25+
enable_snap_start = true
2526
}
2627
}
2728

@@ -135,6 +136,21 @@ run "lambda_function_vpc_configuration" {
135136
}
136137
}
137138

139+
run "lambda_function_snap_start" {
140+
141+
command = plan
142+
143+
assert {
144+
condition = length(aws_lambda_function.lambda_application["api"].snap_start) == 0
145+
error_message = "API function should not have snap start configuration"
146+
}
147+
148+
assert {
149+
condition = length(aws_lambda_function.lambda_application["worker"].snap_start) > 0
150+
error_message = "Worker function should have snap start configuration"
151+
}
152+
}
153+
138154
run "service_catalog_application_registration" {
139155
command = plan
140156

variables.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ variable "lambda_functions_config" {
2424
application_log_level = optional(string)
2525
system_log_level = optional(string)
2626
s3_key = optional(string)
27+
enable_snap_start = optional(bool, false)
2728

2829
function_concurrency_limit = optional(number)
2930
}))

0 commit comments

Comments
 (0)