forked from JJGuilloryGit/project3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
03-policies.tf
37 lines (32 loc) · 1003 Bytes
/
03-policies.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
data "aws_iam_policy_document" "group_policies" {
for_each = var.group_policies
statement {
effect = "Allow"
actions = each.value
resources = ["*"]
}
}
resource "aws_iam_group_policy" "group_specific_policy" {
for_each = var.group_policies
name = "${each.key}-policy"
group = aws_iam_group.group[each.key].name
policy = data.aws_iam_policy_document.group_policies[each.key].json
}
data "aws_iam_policy_document" "mfa_policy" {
statement {
effect = "Allow"
actions = ["sts:GetSessionToken"]
resources = ["*"]
condition {
test = "BoolIfExists"
variable = "aws:MultiFactorAuthPresent"
values = ["true"]
}
}
}
resource "aws_iam_group_policy" "mfa_policy" {
for_each = { for k in var.mfa_enabled_groups : k => var.iam_groups[k] if contains(keys(var.iam_groups), k) }
name = "${each.key}-mfa-policy"
group = aws_iam_group.group[each.key].name
policy = data.aws_iam_policy_document.mfa_policy.json
}