-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
39 lines (38 loc) · 1.18 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
data "aws_iam_policy_document" "assume_role" {
statement {
effect = "Allow"
principals {
type = "Federated"
identifiers = ["arn:aws:iam::${var.account_id}:oidc-provider/${var.gh_idp}"]
}
actions = ["sts:AssumeRoleWithWebIdentity"]
condition {
test = "StringEquals"
variable = "${var.gh_idp}:aud"
values = [var.gh_idp_aud]
}
condition {
test = "StringEquals"
variable = "${var.gh_idp}:sub"
values = concat([
for branch in var.branches :
"repo:${var.owner}/${var.repo}:ref:refs/heads/${branch}"
], [
for environment in var.environments :
"repo:${var.owner}/${var.repo}:environment:${environment}"
])
}
}
}
resource "aws_iam_role" "this" {
name = "GitHubActions-${var.owner}-${var.repo}-${join("_", concat(tolist(var.branches), tolist(var.environments)))}"
assume_role_policy = data.aws_iam_policy_document.assume_role.json
managed_policy_arns = var.policy_arns
dynamic "inline_policy" {
for_each = var.inline_policies
content {
name = inline_policy.value["name"]
policy = inline_policy.value["policy"]
}
}
}