Skip to content

Commit d6f2b10

Browse files
committed
Set package_type to Image when image_uri is specified. Otherwise specify (previous default) Zip
1 parent 6541720 commit d6f2b10

File tree

4 files changed

+206
-0
lines changed

4 files changed

+206
-0
lines changed

main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ resource "aws_lambda_function" "lambda_function" {
1414
memory_size = var.memory_size
1515
reserved_concurrent_executions = var.reserved_concurrent_executions
1616
tags = var.tags
17+
package_type = var.image_uri != "" ? "Image" : "Zip"
1718

1819
vpc_config {
1920
subnet_ids = var.subnet_ids
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
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": "unused",
109+
"image_config": [],
110+
"image_uri": "image",
111+
"kms_key_arn": null,
112+
"layers": null,
113+
"memory_size": 128,
114+
"package_type": "Image",
115+
"publish": false,
116+
"reserved_concurrent_executions": -1,
117+
"runtime": "provided",
118+
"s3_bucket": null,
119+
"s3_key": null,
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+
"qualified_arn": true,
143+
"role": true,
144+
"signing_job_arn": true,
145+
"signing_profile_version_arn": true,
146+
"source_code_hash": true,
147+
"source_code_size": true,
148+
"tracing_config": true,
149+
"version": true,
150+
"vpc_config": [
151+
{
152+
"vpc_id": true
153+
}
154+
]
155+
}
156+
}
157+
}
158+
]
159+
}

test/infra_container/main.tf

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
terraform {
2+
required_version = ">= 0.12"
3+
}
4+
5+
provider "aws" {
6+
version = ">= 2.15"
7+
skip_credentials_validation = true
8+
skip_metadata_api_check = true
9+
skip_get_ec2_platforms = true
10+
skip_region_validation = true
11+
skip_requesting_account_id = true
12+
max_retries = 1
13+
access_key = "a"
14+
secret_key = "a"
15+
region = "eu-west-1"
16+
}
17+
18+
module "lambda" {
19+
source = "../.."
20+
image_uri = "image"
21+
function_name = "check_lambda_function"
22+
handler = "unused"
23+
runtime = "provided"
24+
}
25+
26+
output "lambda_function_arn" {
27+
value = module.lambda.lambda_arn
28+
}

test/test_lambda.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,24 @@ def test_all_resources_to_be_created(self):
5555
self.assert_resource_changes_action(resource_changes, 'create', 4)
5656
self.assert_resource_changes('create_lambda', resource_changes)
5757

58+
def test_all_resources_to_be_created_for_container_lambda(self):
59+
# Given When
60+
check_call([
61+
'terraform',
62+
'plan',
63+
'-out=plan.out',
64+
'-no-color',
65+
'test/infra_container'
66+
])
67+
68+
resource_changes = self.get_resource_changes()
69+
70+
# Then
71+
assert len(resource_changes) == 4
72+
self.assert_resource_changes_action(resource_changes, 'create', 4)
73+
self.assert_resource_changes('create_lambda_container', resource_changes)
74+
75+
5876
def test_create_lambda_in_vpc(self):
5977
# Given When
6078
check_call([

0 commit comments

Comments
 (0)