/
users.tf
42 lines (40 loc) · 1.05 KB
/
users.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
variable "user_info" {
description = "Map of AWS IAM usernames, email address tags and custom user tags"
type = map(object({
email = string
user_tags = optional(map(string))
}))
default = {
"userA" = {
email = "userA@jennasrunbooks.com"
}
"userB" = {
email = "userB@jennasrunbooks.com"
user_tags = {
"AKIASRJ6UGTMV3JU6CU2" = "testkey1"
}
}
}
}
resource "aws_iam_user" "this" {
for_each = var.user_info
name = each.key
path = "/"
tags = merge(
var.common_tags,
{
email = each.value.email
},
each.value.user_tags
)
# Provisions the login profile for each new user and outputs their temp login password
provisioner "local-exec" {
when = create
command = "python ../../scripts/aws_iam_user_password_reset.py profile -u ${each.key}"
}
# Destroys the login profile, MFA devices and access keys for each removed user
provisioner "local-exec" {
when = destroy
command = "python ../../scripts/aws_iam_user_cleanup.py ${each.key}"
}
}