Skip to content
This repository has been archived by the owner on Jun 14, 2021. It is now read-only.

Commit

Permalink
Support updating recovery credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
vijetm committed Nov 15, 2019
1 parent 4d300d4 commit 9732d9d
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion okta/resource_okta_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ func resourceUser() *schema.Resource {
Type: schema.TypeString,
Optional: true,
Sensitive: true,
ValidateFunc: validation.StringLenBetween(8, 1000), // Hope no one uses password > 1000 chars
Description: "User Password",
},
"recovery_question": &schema.Schema{
Expand Down Expand Up @@ -430,6 +429,8 @@ func resourceUserUpdate(d *schema.ResourceData, m interface{}) error {
groupChange := d.HasChange("group_memberships")
userChange := hasProfileChange(d)
passwordChange := d.HasChange("password")
recoveryQuestionChange := d.HasChange("recovery_question")
recoveryAnswerChange := d.HasChange("recovery_answer")

// run the update status func first so a user that was previously deprovisioned
// can be updated further if it's status changed in it's terraform configs
Expand Down Expand Up @@ -491,6 +492,28 @@ func resourceUserUpdate(d *schema.ResourceData, m interface{}) error {
}
}

if recoveryQuestionChange || recoveryAnswerChange {
p := &okta.PasswordCredential{
Value: d.Get("password").(string),
}

rq := &okta.RecoveryQuestionCredential{
Question: d.Get("recovery_question").(string),
Answer: d.Get("recovery_answer").(string),
}

nuc := &okta.UserCredentials{
Password: p,
RecoveryQuestion: rq,
}

_, _, err := client.User.ChangeRecoveryQuestion(d.Id(), *nuc)

if err != nil {
return fmt.Errorf("[ERROR] Error Updating User password recovery credentials in Okta: %v", err)
}
}

d.Partial(false)

return resourceUserRead(d, m)
Expand Down

0 comments on commit 9732d9d

Please # to comment.