-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
65 lines (56 loc) · 1.8 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
resource "aws_iam_role" "main" {
name = var.name
assume_role_policy = var.require_mfa ? data.aws_iam_policy_document.assume_role_require_mfa.json : data.aws_iam_policy_document.assume_role.json
description = var.description
force_detach_policies = var.force_detach_policies
max_session_duration = var.max_session_duration
name_prefix = var.name_prefix
path = var.path
permissions_boundary = var.permissions_boundary
tags = var.tags
}
resource "aws_iam_role_policy_attachment" "main" {
count = length(var.policy_arns) > 0 ? length(var.policy_arns) : 0
role = aws_iam_role.main.name
policy_arn = element(var.policy_arns, count.index)
}
data "aws_iam_policy_document" "assume_role" {
statement {
actions = ["sts:AssumeRole"]
effect = "Allow"
principals {
identifiers = var.trusted_arns
type = "AWS"
}
principals {
identifiers = var.trusted_services
type = "Service"
}
sid = ""
}
}
data "aws_iam_policy_document" "assume_role_require_mfa" {
statement {
actions = ["sts:AssumeRole"]
condition {
test = "Bool"
values = ["true"]
variable = "aws:MultiFactorAuthPresent"
}
condition {
test = "NumericLessThan"
values = [var.mfa_age]
variable = "aws:MultiFactorAuthAge"
}
effect = "Allow"
principals {
identifiers = var.trusted_arns
type = "AWS"
}
principals {
identifiers = var.trusted_services
type = "Service"
}
sid = ""
}
}