Skip to content

Commit 38ee16d

Browse files
authored
Merge pull request #10 from mmgcarlos/master
NEWKYCSIX-1119: Adding layers to lambda module
2 parents d696497 + cded5b5 commit 38ee16d

10 files changed

+206
-5
lines changed

main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ resource "aws_lambda_function" "lambda_function" {
1515
reserved_concurrent_executions = var.reserved_concurrent_executions
1616
tags = var.tags
1717
package_type = var.image_uri != "" ? "Image" : "Zip"
18+
layers = var.layers
1819

1920
vpc_config {
2021
subnet_ids = var.subnet_ids

test/files/create_lambda.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
"image_config": [],
110110
"image_uri": null,
111111
"kms_key_arn": null,
112-
"layers": null,
112+
"layers": [],
113113
"memory_size": 128,
114114
"package_type": "Zip",
115115
"publish": false,
@@ -139,6 +139,7 @@
139139
"image_config": [],
140140
"invoke_arn": true,
141141
"last_modified": true,
142+
"layers": [],
142143
"qualified_arn": true,
143144
"role": true,
144145
"signing_job_arn": true,

test/files/create_lambda_container.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
"image_config": [],
110110
"image_uri": "image",
111111
"kms_key_arn": null,
112-
"layers": null,
112+
"layers": [],
113113
"memory_size": 128,
114114
"package_type": "Image",
115115
"publish": false,
@@ -139,6 +139,7 @@
139139
"image_config": [],
140140
"invoke_arn": true,
141141
"last_modified": true,
142+
"layers": [],
142143
"qualified_arn": true,
143144
"role": true,
144145
"signing_job_arn": true,

test/files/create_lambda_in_vpc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
"image_config": [],
132132
"image_uri": null,
133133
"kms_key_arn": null,
134-
"layers": null,
134+
"layers": [],
135135
"memory_size": 128,
136136
"package_type": "Zip",
137137
"publish": false,
@@ -167,6 +167,7 @@
167167
"image_config": [],
168168
"invoke_arn": true,
169169
"last_modified": true,
170+
"layers": [],
170171
"qualified_arn": true,
171172
"role": true,
172173
"signing_job_arn": true,
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
{
2+
"resource_changes": [
3+
{
4+
"address": "module.lambda.aws_cloudwatch_log_group.lambda_loggroup",
5+
"module_address": "module.lambda",
6+
"mode": "managed",
7+
"type": "aws_cloudwatch_log_group",
8+
"name": "lambda_loggroup",
9+
"provider_name": "aws",
10+
"change": {
11+
"actions": [
12+
"create"
13+
],
14+
"before": null,
15+
"after": {
16+
"kms_key_id": null,
17+
"name": "/aws/lambda/check_lambda_function",
18+
"name_prefix": null,
19+
"retention_in_days": 7,
20+
"tags": null
21+
},
22+
"after_unknown": {
23+
"arn": true,
24+
"id": true
25+
}
26+
}
27+
},
28+
{
29+
"address": "module.lambda.aws_iam_role.iam_for_lambda",
30+
"module_address": "module.lambda",
31+
"mode": "managed",
32+
"type": "aws_iam_role",
33+
"name": "iam_for_lambda",
34+
"provider_name": "aws",
35+
"change": {
36+
"actions": [
37+
"create"
38+
],
39+
"before": null,
40+
"after": {
41+
"assume_role_policy": "{\n \"Version\": \"2012-10-17\",\n \"Statement\": [\n {\n \"Action\": \"sts:AssumeRole\",\n \"Principal\": {\n \"Service\": \"lambda.amazonaws.com\"\n },\n \"Effect\": \"Allow\"\n }\n ]\n}\n",
42+
"description": null,
43+
"force_detach_policies": false,
44+
"max_session_duration": 3600,
45+
"name_prefix": "check_lambda_function",
46+
"path": "/",
47+
"permissions_boundary": null,
48+
"tags": null
49+
},
50+
"after_unknown": {
51+
"arn": true,
52+
"create_date": true,
53+
"id": true,
54+
"inline_policy": true,
55+
"managed_policy_arns": true,
56+
"name": true,
57+
"unique_id": true
58+
}
59+
}
60+
},
61+
{
62+
"address": "module.lambda.aws_iam_role_policy.lambda_policy",
63+
"module_address": "module.lambda",
64+
"mode": "managed",
65+
"type": "aws_iam_role_policy",
66+
"name": "lambda_policy",
67+
"provider_name": "aws",
68+
"change": {
69+
"actions": [
70+
"create"
71+
],
72+
"before": null,
73+
"after": {
74+
"name": "policy",
75+
"name_prefix": null,
76+
"policy": "{\n \"Statement\": [\n {\n \"Effect\": \"Allow\",\n \"Action\": [\n \"logs:CreateLogGroup\",\n \"logs:CreateLogStream\",\n \"logs:PutLogEvents\"\n ],\n \"Resource\": \"arn:aws:logs:*:*:*\"\n }\n ]\n}\n"
77+
},
78+
"after_unknown": {
79+
"id": true,
80+
"role": true
81+
}
82+
}
83+
},
84+
{
85+
"address": "module.lambda.aws_lambda_function.lambda_function",
86+
"module_address": "module.lambda",
87+
"mode": "managed",
88+
"type": "aws_lambda_function",
89+
"name": "lambda_function",
90+
"provider_name": "aws",
91+
"change": {
92+
"actions": [
93+
"create"
94+
],
95+
"before": null,
96+
"after": {
97+
"code_signing_config_arn": null,
98+
"dead_letter_config": [],
99+
"description": null,
100+
"environment": [
101+
{
102+
"variables": null
103+
}
104+
],
105+
"file_system_config": [],
106+
"filename": null,
107+
"function_name": "check_lambda_function",
108+
"handler": "some_handler",
109+
"image_config": [],
110+
"image_uri": null,
111+
"kms_key_arn": null,
112+
"layers": [ "arn:aws:lambda:eu-west-1:aws:r1" ],
113+
"memory_size": 128,
114+
"package_type": "Zip",
115+
"publish": false,
116+
"reserved_concurrent_executions": -1,
117+
"runtime": "python3.7",
118+
"s3_bucket": "cdflow-lambda-releases",
119+
"s3_key": "s3key.zip",
120+
"s3_object_version": null,
121+
"tags": null,
122+
"timeout": 3,
123+
"timeouts": null,
124+
"vpc_config": [
125+
{
126+
"security_group_ids": null,
127+
"subnet_ids": null
128+
}
129+
]
130+
},
131+
"after_unknown": {
132+
"arn": true,
133+
"dead_letter_config": [],
134+
"environment": [
135+
{}
136+
],
137+
"file_system_config": [],
138+
"id": true,
139+
"image_config": [],
140+
"invoke_arn": true,
141+
"last_modified": true,
142+
"layers": [ false ],
143+
"qualified_arn": true,
144+
"role": true,
145+
"signing_job_arn": true,
146+
"signing_profile_version_arn": true,
147+
"source_code_hash": true,
148+
"source_code_size": true,
149+
"tracing_config": true,
150+
"version": true,
151+
"vpc_config": [
152+
{
153+
"vpc_id": true
154+
}
155+
]
156+
}
157+
}
158+
}
159+
]
160+
}

test/files/create_lambda_with_reserved_concurrent_executions.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
"image_config": [],
110110
"image_uri": null,
111111
"kms_key_arn": null,
112-
"layers": null,
112+
"layers": [],
113113
"memory_size": 128,
114114
"package_type": "Zip",
115115
"publish": false,
@@ -139,6 +139,7 @@
139139
"image_config": [],
140140
"invoke_arn": true,
141141
"last_modified": true,
142+
"layers": [],
142143
"qualified_arn": true,
143144
"role": true,
144145
"signing_job_arn": true,

test/files/create_lambda_with_tags.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
"image_config": [],
110110
"image_uri": null,
111111
"kms_key_arn": null,
112-
"layers": null,
112+
"layers": [],
113113
"memory_size": 128,
114114
"package_type": "Zip",
115115
"publish": false,
@@ -142,6 +142,7 @@
142142
"image_config": [],
143143
"invoke_arn": true,
144144
"last_modified": true,
145+
"layers": [],
145146
"qualified_arn": true,
146147
"role": true,
147148
"signing_job_arn": true,

test/infra/main.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ module "lambda" {
2727
security_group_ids = var.security_group_ids
2828
reserved_concurrent_executions = var.reserved_concurrent_executions
2929
tags = var.tags
30+
layers = var.layers
3031
}
3132

3233
variable "subnet_ids" {
@@ -58,6 +59,12 @@ variable "tags" {
5859
default = {}
5960
}
6061

62+
variable "layers" {
63+
type = list(string)
64+
description = "ARNs of the layers to attach to the lambda function in order"
65+
default = []
66+
}
67+
6168
output "lambda_function_arn" {
6269
value = module.lambda.lambda_arn
6370
}

test/test_lambda.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,25 @@ def test_create_lambda_with_tags(self):
133133
'create_lambda_with_tags',
134134
resource_changes
135135
)
136+
137+
def test_create_lambda_with_layers(self):
138+
# Given When
139+
check_call([
140+
'terraform',
141+
'plan',
142+
'-out=plan.out',
143+
'-var', 'layers=["arn:aws:lambda:eu-west-1:aws:r1"]',
144+
'-no-color',
145+
'test/infra'
146+
])
147+
148+
resource_changes = self.get_resource_changes()
149+
150+
# Then
151+
assert len(resource_changes) == 4
152+
self.assert_resource_changes_action(resource_changes, 'create', 4)
153+
self.assert_resource_changes(
154+
'create_lambda_with_layers',
155+
resource_changes
156+
)
157+

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,9 @@ variable "tags" {
9393
type = map(string)
9494
default = {}
9595
}
96+
97+
variable "layers" {
98+
type = list(string)
99+
description = "ARNs of the layers to attach to the lambda function in order"
100+
default = []
101+
}

0 commit comments

Comments
 (0)