@@ -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 )
0 commit comments