-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathiam.tf
57 lines (49 loc) · 1.71 KB
/
iam.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
# Policy granting Lambda the ability to assume the role we're creating
data "aws_iam_policy_document" "lambda-assume-role-policy" {
statement {
effect = "Allow"
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["lambda.amazonaws.com"]
}
}
}
# Policy attached to the IAM role we're creating
data "aws_iam_policy_document" "lambda-role-policy" {
# Permit the Lambda function to write to CloudWatch Logs
statement {
sid = "AllowCloudWatchLogs"
effect = "Allow"
actions = ["logs:*"]
resources = ["*"]
}
# Permit the Lambda function to get a WAF change token
statement {
sid = "AllowWAFGetChangeToken"
effect = "Allow"
actions = ["waf:GetChangeToken"]
resources = ["*"]
}
# Permit the Lambda function to update IP sets
statement {
sid = "AllowGetUpdateWAFIPSet"
effect = "Allow"
actions = ["waf:GetIPSet", "waf:UpdateIPSet"]
resources = [
"arn:aws:waf::${data.aws_caller_identity.current.account_id}:ipset/${aws_cloudformation_stack.waf-ipsets-and-rules.outputs["WAFIPSet1"]}",
"arn:aws:waf::${data.aws_caller_identity.current.account_id}:ipset/${aws_cloudformation_stack.waf-ipsets-and-rules.outputs["WAFIPSet2"]}"
]
}
}
resource "aws_iam_role" "lambda" {
provider = "aws.terraform-aws-waf-drop"
name_prefix = "aws_waf_drop_updater_"
assume_role_policy = "${data.aws_iam_policy_document.lambda-assume-role-policy.json}"
}
resource "aws_iam_role_policy" "lambda" {
provider = "aws.terraform-aws-waf-drop"
name = "aws_waf_drop_updater_lambda_policy"
role = "${aws_iam_role.lambda.id}"
policy = "${data.aws_iam_policy_document.lambda-role-policy.json}"
}