Skip to content

Commit fdb8223

Browse files
authored
feat(#2535): add support for realm_id in okta_user resource and data_… (#2536)
1 parent 241e859 commit fdb8223

24 files changed

Lines changed: 18213 additions & 21949 deletions

File tree

okta/services/idaas/data_source_okta_user.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ func dataSourceUser() *schema.Resource {
8585
Default: false,
8686
Description: "Do not populate user roles information (prevents additional API call)",
8787
},
88+
"realm_id": {
89+
Type: schema.TypeString,
90+
Computed: true,
91+
Description: "The Realm ID associated with the user.",
92+
},
8893
}),
8994
Description: "Get a single users from Okta.",
9095
}

okta/services/idaas/data_source_okta_users.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ func dataSourceUsers() *schema.Resource {
5757
Type: schema.TypeString,
5858
Computed: true,
5959
},
60+
"realm_id": {
61+
Type: schema.TypeString,
62+
Computed: true,
63+
Description: "The Realm ID associated with the user.",
64+
},
6065
}),
6166
},
6267
},

okta/services/idaas/resource_okta_user.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,12 @@ func resourceUser() *schema.Resource {
302302
Sensitive: true,
303303
Description: "User Password Recovery Answer",
304304
},
305+
"realm_id": {
306+
Type: schema.TypeString,
307+
Optional: true,
308+
Computed: true,
309+
Description: "The Realm ID to associate the user with",
310+
},
305311
// lintignore:S018
306312
"password_hash": {
307313
Type: schema.TypeSet,
@@ -432,6 +438,11 @@ func resourceUserCreate(ctx context.Context, d *schema.ResourceData, meta interf
432438
Profile: profile,
433439
Credentials: uc,
434440
}
441+
442+
if realmId, ok := d.GetOk("realm_id"); ok {
443+
userBody.RealmId = utils.StringPtr(realmId.(string))
444+
}
445+
435446
client := getOktaClientFromMetadata(meta)
436447
user, _, err := client.User.CreateUser(ctx, userBody, qp)
437448
if err != nil {
@@ -495,6 +506,7 @@ func resourceUserUpdate(ctx context.Context, d *schema.ResourceData, meta interf
495506

496507
// There are a few requests here so just making sure the state gets updated per successful downstream change
497508
userChange := hasProfileChange(d)
509+
realmChange := d.HasChange("realm_id")
498510
passwordChange := d.HasChange("password")
499511
passwordHashChange := d.HasChange("password_hash")
500512
passwordHookChange := d.HasChange("password_inline_hook")
@@ -527,7 +539,7 @@ func resourceUserUpdate(ctx context.Context, d *schema.ResourceData, meta interf
527539
return diag.Errorf("Only the status of a DEPROVISIONED user can be updated, we detected other change")
528540
}
529541

530-
if userChange || passwordHashChange || passwordHookChange {
542+
if userChange || realmChange || passwordHashChange || passwordHookChange {
531543
profile := populateUserProfile(d)
532544
userBody := sdk.User{
533545
Profile: profile,
@@ -549,6 +561,11 @@ func resourceUserUpdate(ctx context.Context, d *schema.ResourceData, meta interf
549561
},
550562
}
551563
}
564+
565+
if realmId, ok := d.GetOk("realm_id"); ok {
566+
userBody.RealmId = utils.StringPtr(realmId.(string))
567+
}
568+
552569
_, _, err := client.User.UpdateUser(ctx, d.Id(), userBody, nil)
553570
if err != nil {
554571
return diag.Errorf("failed to update user: %v", err)

okta/services/idaas/user.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,9 @@ func flattenUser(u *sdk.User, filteredCustomAttributes []string) map[string]inte
403403
}
404404

405405
attrs["status"] = mapStatus(u.Status)
406+
if u.RealmId != nil {
407+
attrs["realm_id"] = u.RealmId
408+
}
406409

407410
data, _ := json.Marshal(customAttributes)
408411
attrs["custom_profile_attributes"] = string(data)

sdk/v2_createUserRequest.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ type CreateUserRequest struct {
66
GroupIds []string `json:"groupIds,omitempty"`
77
Profile *UserProfile `json:"profile,omitempty"`
88
Type *UserType `json:"type,omitempty"`
9+
RealmId *string `json:"realmId,omitempty"`
910
}

sdk/v2_user.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type User struct {
2626
StatusChanged *time.Time `json:"statusChanged,omitempty"`
2727
TransitioningToStatus string `json:"transitioningToStatus,omitempty"`
2828
Type *UserType `json:"type,omitempty"`
29+
RealmId *string `json:"realmId,omitempty"`
2930
}
3031

3132
// Creates a new user in your Okta organization with or without credentials.

0 commit comments

Comments
 (0)