-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathiam.tf
More file actions
62 lines (58 loc) · 1.72 KB
/
iam.tf
File metadata and controls
62 lines (58 loc) · 1.72 KB
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
data "aws_iam_policy_document" "assume_role" {
statement {
effect = "Allow"
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["apigateway.amazonaws.com"]
}
}
}
resource "aws_iam_role" "api_gateway" {
name = "${var.workspace}-${var.api_gateway_name}-role"
assume_role_policy = data.aws_iam_policy_document.assume_role.json
}
data "aws_iam_policy_document" "api_gateway_logging" {
#checkov:skip=CKV_AWS_356: Wildcard permissions needed for global log event reads
statement {
sid = "AllowCreateLogGroup"
effect = "Allow"
actions = [
"logs:CreateLogGroup"
]
resources = [
"arn:aws:logs:${var.region}:${data.aws_caller_identity.current.account_id}:*"
]
}
statement {
sid = "AllowLogStreamAndEvents"
effect = "Allow"
actions = [
"logs:CreateLogStream",
"logs:PutLogEvents"
]
resources = [
"arn:aws:logs:${var.region}:${data.aws_caller_identity.current.account_id}:log-group:/aws/apigateway/*"
]
}
statement {
sid = "AllowDescribeAndGet"
effect = "Allow"
actions = [
"logs:DescribeLogGroups",
"logs:DescribeLogStreams",
"logs:GetLogEvents",
"logs:FilterLogEvents"
]
resources = ["*"]
}
}
resource "aws_iam_policy" "api_gateway_logging" {
name = "${var.workspace}-${var.api_gateway_name}-api-gateway-logging-policy"
description = "Policy to allow API Gateway push logs to Cloudwatch"
policy = data.aws_iam_policy_document.api_gateway_logging.json
}
resource "aws_iam_role_policy_attachment" "api_gateway_logging" {
role = aws_iam_role.api_gateway.name
policy_arn = aws_iam_policy.api_gateway_logging.arn
}