forked from FutureSharks/invokust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
65 lines (58 loc) · 1.83 KB
/
main.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Example terraform configuration for a lambda function that uses invokust to run locust
provider "aws" {
region = "eu-west-1"
}
resource "aws_iam_role" "lambda_basic_execution" {
name = "lambda_basic_execution"
path = "/service-role/"
assume_role_policy = "${data.aws_iam_policy_document.lambda_basic_execution_assume_role.json}"
}
data "aws_iam_policy_document" "lambda_basic_execution_assume_role" {
statement {
effect = "Allow"
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["lambda.amazonaws.com"]
}
}
}
data "aws_iam_policy_document" "lambda_basic_execution" {
statement {
effect = "Allow"
actions = [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
]
resources = ["*"]
}
}
resource "aws_iam_policy" "lambda_basic_execution" {
name = "lambda_basic_execution"
description = "Basic execution policy for a Lambda function"
policy = "${data.aws_iam_policy_document.lambda_basic_execution.json}"
}
resource "aws_iam_policy_attachment" "lambda_basic_execution" {
name = "lambda_basic_execution"
roles = ["${aws_iam_role.lambda_basic_execution.name}"]
policy_arn = "${aws_iam_policy.lambda_basic_execution.arn}"
}
resource "aws_lambda_function" "lambda_locust" {
filename = "lambda_locust.zip"
function_name = "lambda_locust"
role = "${aws_iam_role.lambda_basic_execution.arn}"
handler = "lambda_locust.handler"
runtime = "python3.6"
timeout = 300
description = "A function that runs a locust load test"
environment {
variables = {
LOCUST_RUN_TIME = "3m"
LOCUST_LOCUSTFILE="locustfile_example.py"
LOCUST_HOST="http://example.com"
LOCUST_HATCH_RATE="1"
LOCUST_NUM_CLIENTS="1"
}
}
}