-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
main.tf
46 lines (36 loc) · 1.23 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
data "aws_iam_policy_document" "this" {
count = var.create_role ? 1 : 0
dynamic "statement" {
for_each = var.oidc_providers
content {
effect = "Allow"
actions = ["sts:AssumeRoleWithWebIdentity"]
principals {
type = "Federated"
identifiers = [statement.value.provider_arn]
}
condition {
test = "StringEquals"
variable = "${replace(statement.value.provider_arn, "/^(.*provider/)/", "")}:sub"
values = [for sa in statement.value.namespace_service_accounts : "system:serviceaccount:${sa}"]
}
}
}
}
resource "aws_iam_role" "this" {
count = var.create_role ? 1 : 0
name = var.role_name
name_prefix = var.role_name_prefix
path = var.role_path
description = var.role_description
assume_role_policy = data.aws_iam_policy_document.this[0].json
max_session_duration = var.max_session_duration
permissions_boundary = var.role_permissions_boundary_arn
force_detach_policies = var.force_detach_policies
tags = var.tags
}
resource "aws_iam_role_policy_attachment" "this" {
for_each = toset([for arn in var.role_policy_arns : arn if var.create_role])
role = aws_iam_role.this[0].name
policy_arn = each.key
}