-
Notifications
You must be signed in to change notification settings - Fork 3
/
send-wg-conf.tf
101 lines (93 loc) · 2.44 KB
/
send-wg-conf.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
88
89
90
91
92
93
94
95
96
97
98
99
resource "aws_iam_role" "send_wg_conf" {
name = "${local.name}-send-wg-conf"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Effect = "Allow"
Sid = ""
Principal = {
Service = "lambda.amazonaws.com"
}
}
]
})
}
resource "aws_iam_policy" "send_wg_conf" {
policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ec2:DescribeNetworkInterfaces",
"ec2:CreateNetworkInterface",
"ec2:DeleteNetworkInterface",
"ec2:DescribeInstances",
"ec2:AttachNetworkInterface"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "*"
}
]
}
POLICY
}
resource "aws_iam_policy" "send_wg_conf_ses" {
count = var.wg_admin_email != null ? 1 : 0
policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ses:SendRawEmail"
],
"Resource": "arn:aws:ses:${local.region}:${local.account}:identity/${var.wg_admin_email}"
}
]
}
POLICY
}
resource "aws_iam_role_policy_attachment" "send_wg_conf_ses" {
count = var.wg_admin_email != null ? 1 : 0
policy_arn = aws_iam_policy.send_wg_conf_ses[0].arn
role = aws_iam_role.send_wg_conf.name
}
resource "aws_iam_role_policy_attachment" "send_wg_conf" {
policy_arn = aws_iam_policy.send_wg_conf.arn
role = aws_iam_role.send_wg_conf.name
}
module "send_wg_conf" {
source = "terraform-aws-modules/lambda/aws"
version = "2.7.0"
create_package = true
create_role = false
create = var.wg_admin_email != null ? true : false
create_layer = false
create_function = true
publish = true
function_name = "${local.name}-send-wg-conf"
runtime = "python3.9"
handler = "app.handler"
memory_size = 512
timeout = 30
lambda_role = aws_iam_role.send_wg_conf.arn
package_type = "Zip"
source_path = "${path.module}/lambdas/send-wg-conf"
environment_variables = {
WG_ADMIN_EMAIL = var.wg_admin_email
LOCAL_NAME = local.name
}
}