-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
48 lines (43 loc) · 1.44 KB
/
main.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
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 5.31.0, < 6.0.0"
}
}
}
resource "aws_iam_role" "github_actions_role" {
for_each = {
for index, rp in var.repo_policies :
sha1("${rp.repo}/${join(",", coalescelist(rp.branches, ["*"]))}") => rp
}
name = substr("GithubAction_${substr(md5(join(",", coalescelist(each.value.branches, ["*"]))), 0, 16)}_${replace(each.value.repo, "/", "@")}", 0, 64)
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRoleWithWebIdentity"
Effect = "Allow"
Principal = {
Federated = var.oidc_provider_arn
}
Condition = {
StringLike = {
"token.actions.githubusercontent.com:sub" : contains(coalescelist(each.value.branches, ["*"]), "*") ? "repo:${each.value.repo}:*" : [for branch in each.value.branches : "repo:${each.value.repo}:ref:refs/heads/${branch}"]
}
StringEquals = {
"token.actions.githubusercontent.com:aud" : "sts.amazonaws.com"
}
}
},
]
})
managed_policy_arns = each.value.managed_policy_arns
dynamic "inline_policy" {
for_each = each.value.inline_policy != null && length(each.value.inline_policy) > 0 ? [each.value.inline_policy] : []
content {
name = "GithubAction_Policy_${replace(each.key, "/", "@")}"
policy = inline_policy.value
}
}
}