forked from bacchus-snu/infra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiam.tf
124 lines (110 loc) · 2.78 KB
/
iam.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
locals {
users = {
"tirr" = {
pgp_key = "keybase:vbchunguk",
is_admin = true,
console_enabled = true,
},
"ryul99" = {
pgp_key = "keybase:ryul_99",
is_admin = true,
console_enabled = true,
},
"skystar" = {
pgp_key = "keybase:skystar",
is_admin = true,
console_enabled = true,
},
"cseteram" = {
pgp_key = "keybase:cseteram",
is_admin = true,
console_enabled = true,
},
"jhuni" = {
pgp_key = "keybase:jhuni",
is_admin = true,
console_enabled = true,
},
"whnbaek" = {
pgp_key = file("./keys/whnbaek.gpg"),
is_admin = true,
console_enabled = true,
},
"nevivurn" = {
pgp_key = file("./keys/nevivurn.gpg"),
is_admin = true,
console_enabled = true,
},
"minty99" = {
pgp_key = "keybase:minty99",
is_admin = true,
console_enabled = true,
},
"vexatone" = {
pgp_key = file("./keys/vexatone.gpg"),
is_admin = true,
console_enabled = true,
},
"songmin" = {
pgp_key = "keybase:smintree99",
is_admin = true,
console_enabled = true,
},
"terraform-cloud" = {
pgp_key = "",
is_admin = true,
console_enabled = false,
},
}
}
data "aws_iam_policy" "administrator_access" {
name = "AdministratorAccess"
}
resource "aws_iam_user" "bacchus" {
for_each = local.users
name = each.key
path = "/"
}
resource "aws_iam_user_login_profile" "bacchus" {
for_each = {
for user in aws_iam_user.bacchus :
user.name => local.users[user.name]["pgp_key"]
if local.users[user.name]["console_enabled"]
}
user = each.key
pgp_key = each.value == "" ? null : each.value
password_reset_required = true
lifecycle {
ignore_changes = [
pgp_key,
password_length,
password_reset_required,
]
}
}
resource "aws_iam_access_key" "bacchus" {
for_each = {
for user in aws_iam_user.bacchus :
user.name => local.users[user.name]["pgp_key"]
}
user = each.key
pgp_key = each.value == "" ? null : each.value
lifecycle {
ignore_changes = [
pgp_key,
]
}
}
resource "aws_iam_group" "bacchus_admin" {
name = "bacchus-admin"
path = "/"
}
resource "aws_iam_group_policy_attachment" "bacchus_admin" {
group = aws_iam_group.bacchus_admin.name
policy_arn = data.aws_iam_policy.administrator_access.arn
}
resource "aws_iam_group_membership" "bacchus_admin" {
name = "bacchus_admin_membership"
group = aws_iam_group.bacchus_admin.name
users = [for user in aws_iam_user.bacchus : user.name if local.users[user.name]["is_admin"]]
}