-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.tf
40 lines (36 loc) · 1.16 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
# iam role module
resource "aws_iam_role" "role" {
name = local.name
assume_role_policy = data.aws_iam_policy_document.trustrel.json
max_session_duration = var.session_duration
}
data "aws_iam_policy_document" "trustrel" {
statement {
effect = "Allow"
actions = ["sts:AssumeRole"]
dynamic "principals" {
for_each = { for k, v in var.principals : k => v if contains(["aws", "service"], k) }
content {
type = lower(principals.key) == "aws" ? upper(principals.key) : title(principals.key)
identifiers = principals.value
}
}
}
statement {
effect = "Allow"
actions = ["sts:AssumeRoleWithWebIdentity"]
dynamic "principals" {
for_each = { for k, v in var.principals : k => v if contains(["federated"], k) }
content {
type = lower(principals.key) == "federated" ? "Federated" : title(principals.key)
identifiers = principals.value
}
}
}
}
# security/policy
resource "aws_iam_role_policy_attachment" "policy" {
count = length(var.policy_arn)
policy_arn = element(var.policy_arn, count.index)
role = aws_iam_role.role.name
}