-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
142 lines (108 loc) · 3.39 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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
locals {
metadata = {
package = "terraform-okta-modules"
version = trimspace(file("${path.module}/../../VERSION"))
module = basename(path.module)
name = var.email
}
module_tags = {
"module.terraform.io/package" = local.metadata.package
"module.terraform.io/version" = local.metadata.version
"module.terraform.io/name" = local.metadata.module
"module.terraform.io/full-name" = "${local.metadata.package}/${local.metadata.module}"
"module.terraform.io/instance" = local.metadata.name
}
}
###################################################
# Okta User
###################################################
# INFO: TODO
# - `user_type`
# INFO: Not supported attributes
# - `password`
# - `expire_password_on_create`
# - `old_password`
# - `password_inline_hook`
# - `recovery_question`
# - `recovery_answer`
# - `password hash`
resource "okta_user" "this" {
login = var.username
status = var.status
## Name
first_name = var.first_name
middle_name = var.middle_name
last_name = var.last_name
honorific_prefix = var.honorific_prefix
honorific_suffix = var.honorific_suffix
nick_name = var.nick_name
display_name = var.display_name
## Contacts
email = var.email
second_email = var.secondary_email
mobile_phone = var.phone
primary_phone = var.primary_phone
profile_url = var.profile_url
## Address
country_code = var.address_info.country_code
state = var.address_info.state
city = var.address_info.city
street_address = var.address_info.street_address
postal_address = var.address_info.postal_address
zip_code = var.address_info.zip_code
## Organizational Information
employee_number = var.employee_number
title = var.title
manager = var.manager.name
manager_id = var.manager.id
organization = var.organization
division = var.division
department = var.department
cost_center = var.cost_center
## Custom Attributes
custom_profile_attributes = jsonencode(var.custom_attributes)
custom_profile_attributes_to_ignore = var.custom_attributes_to_ignore
## Preferences
locale = var.locale
timezone = var.timezone
preferred_language = var.preferred_language
}
###################################################
# Roles of Okta User
###################################################
resource "okta_user_admin_roles" "this" {
user_id = okta_user.this.id
admin_roles = [
for assignment in var.admin_role_assignments :
assignment.admin_role
]
disable_notifications = !var.admin_role_notification_enabled
}
resource "okta_admin_role_targets" "this" {
for_each = {
for assignment in var.admin_role_assignments :
assignment.admin_role => assignment
if length(assignment.target_groups) > 0 || length(assignment.target_apps) > 0
}
user_id = okta_user.this.id
role_type = each.key
apps = (length(each.value.target_apps) > 0
? each.value.target_apps
: null
)
groups = (length(each.value.target_groups) > 0
? each.value.target_groups
: null
)
}
###################################################
# Group Membership
###################################################
resource "okta_user_group_memberships" "this" {
user_id = okta_user.this.id
groups = var.groups
}
data "okta_group" "this" {
for_each = toset(okta_user_group_memberships.this.groups)
id = each.value
}