-
Notifications
You must be signed in to change notification settings - Fork 0
/
iam.tf
59 lines (48 loc) · 1.72 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
resource "aws_iam_role" "github_actions" {
name = var.role_name
assume_role_policy = data.aws_iam_policy_document.github_oidc_assume_role.json
}
data "aws_iam_policy_document" "github_oidc_assume_role" {
#checkov:skip=CKV_AWS_358 "Skipping as this is controlled by variable validation"
version = "2012-10-17"
statement {
effect = "Allow"
actions = ["sts:AssumeRoleWithWebIdentity"]
principals {
type = "Federated"
identifiers = [
"arn:aws:iam::${data.aws_caller_identity.current.account_id}:oidc-provider/token.actions.githubusercontent.com"
]
}
condition {
test = "StringEquals"
variable = "token.actions.githubusercontent.com:aud"
values = ["sts.amazonaws.com"]
}
condition {
test = "StringLike"
variable = "token.actions.githubusercontent.com:sub"
values = formatlist("repo:%s", var.github_repositories)
}
}
}
resource "aws_iam_role_policy_attachment" "read_only" {
role = aws_iam_role.github_actions.name
policy_arn = "arn:aws:iam::aws:policy/ReadOnlyAccess"
}
resource "aws_iam_role_policy_attachment" "additional_managed_policies" {
for_each = toset(var.additional_managed_policies)
role = aws_iam_role.github_actions.name
policy_arn = each.key
}
# Add actions missing from arn:aws:iam::aws:policy/ReadOnlyAccess
resource "aws_iam_policy" "extra_permissions" {
name = var.role_name
path = "/"
description = "A policy for extra permissions for GitHub Actions"
policy = var.additional_permissions
}
resource "aws_iam_role_policy_attachment" "extra_permissions" {
role = aws_iam_role.github_actions.name
policy_arn = aws_iam_policy.extra_permissions.arn
}