-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.tf
87 lines (71 loc) · 2.47 KB
/
test.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Terraform configuration to use together with Localstack
// Resources created in this section will only be used to run the test suite.
// After starting the localstack, you can apply this Terraform config to create
// a fully functional testing environment. See README.md for more details.
provider "aws" {
access_key = "mock_access_key"
region = "us-east-1"
s3_force_path_style = true
secret_key = "mock_secret_key"
skip_credentials_validation = true
skip_metadata_api_check = true
skip_requesting_account_id = true
endpoints {
iam = "http://localhost:4566"
lambda = "http://localhost:4566"
s3 = "http://localhost:4566"
}
}
resource "aws_s3_bucket" "test_bucket" {
bucket = "test-bucket"
acl = "public-read-write"
}
resource "aws_s3_bucket_object" "test_lambda" {
bucket = aws_s3_bucket.test_bucket.bucket
key = "test-lambda/1.0.0/index.zip"
source = "fixtures/index.zip"
etag = filemd5("fixtures/index.zip")
}
data "aws_iam_policy_document" "test_lambda" {
version = "2012-10-17"
statement {
actions = ["sts:AssumeRole"]
effect = "Allow"
principals {
type = "Service"
identifiers = ["lambda.amazonaws.com"]
}
}
}
resource "aws_iam_role" "test_lambda" {
name = "test-lambda-role"
assume_role_policy = data.aws_iam_policy_document.test_lambda.json
description = "A role that can be assumed by the test lambda"
}
data "aws_iam_policy" "test_lambda_execution" {
arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
}
resource "aws_iam_role_policy_attachment" "test_lambda_execution" {
role = aws_iam_role.test_lambda.id
policy_arn = data.aws_iam_policy.test_lambda_execution.arn
}
resource "aws_lambda_function" "test_lambda" {
function_name = "test-lambda"
description = "A lambda function used for testing purposes"
handler = "main"
runtime = "go1.x"
memory_size = 128
timeout = 5
s3_bucket = aws_s3_bucket.test_bucket.bucket
s3_key = aws_s3_bucket_object.test_lambda.key
role = aws_iam_role.test_lambda.arn
}
resource "aws_lambda_alias" "test_lambda" {
name = "live"
description = "Live version of the lambda. Gradual traffic shifting in place."
function_name = aws_lambda_function.test_lambda.arn
function_version = "$LATEST"
lifecycle {
ignore_changes = [function_version]
}
}