-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiam.tf
71 lines (61 loc) · 1.78 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
data "aws_iam_policy_document" "lambda_assume_role" {
statement {
effect = "Allow"
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["lambda.amazonaws.com"]
}
}
}
data "aws_iam_policy_document" "state_file_access" {
statement {
effect = "Allow"
actions = ["logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents"]
resources = ["arn:aws:logs:*:*:*"]
}
statement {
effect = "Allow"
actions = [
"ecr:GetDownloadUrlForLayer",
"ecr:GetAuthorizationToken",
"ecr:BatchCheckLayerAvailability",
"ecr:BatchGetImage"
]
resources = [local.image_arn]
}
statement {
effect = "Allow"
actions = ["s3:PutObject"]
resources = ["arn:aws:s3:::${var.state_bucket}/${var.organization_id}/*"]
}
dynamic "statement" {
for_each = local.grouped_by_bucket
content {
actions = [
"s3:GetObject",
"s3:ListBucket",
]
resources = concat(
["arn:aws:s3:::${statement.key}"],
[for prefix in statement.value[0] : "arn:aws:s3:::${statement.key}/${prefix}"]
)
}
}
}
resource "aws_iam_policy" "state_file_access" {
name = "infracost-state-file-access"
description = "Policy to allow access to state files"
policy = data.aws_iam_policy_document.state_file_access.json
}
resource "aws_iam_role" "state_file_parser" {
name = "infracost-state-parser-role"
assume_role_policy = data.aws_iam_policy_document.lambda_assume_role.json
}
resource "aws_iam_role_policy_attachment" "state_file_access_policy_attachement" {
role = aws_iam_role.state_file_parser.name
policy_arn = aws_iam_policy.state_file_access.arn
}
output "iam_role_arn" {
value = aws_iam_role.state_file_parser.arn
}