-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusers.tf
66 lines (57 loc) · 1.73 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
locals {
users = { for u in var.users : u.alias => u }
}
resource "vault_auth_backend" "password_auth_method" {
type = "userpass"
path = "pw"
tune {
max_lease_ttl = "86400s"
listing_visibility = "unauth"
}
}
resource "vault_generic_endpoint" "user_pw_login" {
for_each = local.users
ignore_absent_fields = true
path = "auth/${vault_auth_backend.password_auth_method.path}/users/${each.key}"
lifecycle {
ignore_changes = [
data_json
]
}
data_json = <<EOT
{
"policies": [${join(", ", formatlist("\"%s\"", each.value.policies.from_auth))}],
"password": "password"
}
EOT
}
resource "vault_identity_entity" "user_entity" {
for_each = local.users
name = each.key
external_policies = each.value.identity.external_policies
metadata = each.value.metadata
}
resource "vault_identity_entity_policies" "user_policies" {
for_each = local.users
depends_on = [vault_identity_entity.user_entity]
policies = each.value.policies.from_entity
exclusive = each.value.identity.exclusive
entity_id = vault_identity_entity.user_entity[each.key].id
}
resource "vault_identity_entity_alias" "user_alias" {
for_each = local.users
name = each.key
mount_accessor = vault_auth_backend.password_auth_method.accessor
canonical_id = vault_identity_entity.user_entity[each.key].id
}
locals {
created_users = { for k in keys(local.users) : k => {
entity_id : vault_identity_entity.user_entity[k].id
policies : vault_identity_entity.user_entity[k].policies
metadata : local.users[k].metadata
} }
}
output "created_users" {
depends_on = [vault_identity_entity_alias.user_alias]
value = local.created_users
}