forked from claranet/terraform-aws-packer-cleanup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lambda.tf
51 lines (41 loc) · 990 Bytes
/
lambda.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
module "lambda" {
source = "github.com/claranet/terraform-aws-lambda?ref=v0.12.0"
function_name = "${var.name}"
description = "Cleans up Packer resources"
handler = "main.lambda_handler"
runtime = "python3.6"
layers = "${var.lambda_layers}"
timeout = 300
source_path = "${path.module}/lambda"
attach_policy = true
policy = "${data.aws_iam_policy_document.lambda.json}"
}
data "aws_iam_policy_document" "lambda" {
statement {
effect = "Allow"
actions = [
"ec2:DescribeInstances",
"ec2:DescribeKeyPairs",
"ec2:DescribeSecurityGroups",
"ec2:DeleteKeyPair",
"ec2:DeleteSecurityGroup",
]
resources = [
"*",
]
}
statement {
effect = "Allow"
actions = [
"ec2:TerminateInstances",
]
resources = [
"*",
]
condition {
test = "StringEquals"
variable = "ec2:ResourceTag/Name"
values = ["Packer Builder"]
}
}
}