Skip to content
This repository has been archived by the owner on Sep 21, 2020. It is now read-only.

Commit

Permalink
fix unassigning roles
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkappa committed Feb 18, 2020
1 parent 32d71cd commit 6b3dce4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ ENHANCEMENTS:
* `resource/auth0_client`: add `initiate_login_uri` ([#2](https://github.com/terraform-providers/terraform-provider-auth0/pull/2))
* `resource/auth0_tenant`: add `default_redirection_uri` ([#2](https://github.com/terraform-providers/terraform-provider-auth0/pull/2))

BUG FIXES:

* resource/auth0_user: unassiging a role won't fail if the role has already been deleted.

## 0.5.1 (January 29, 2020)

Initial release under releases.hashicorp.com
Expand Down
13 changes: 11 additions & 2 deletions auth0/resource_auth0_user.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package auth0

import (
"fmt"
"net/http"
"strings"

Expand Down Expand Up @@ -200,7 +201,7 @@ func updateUser(d *schema.ResourceData, m interface{}) error {
d.Partial(true)
err = assignUserRoles(d, m)
if err != nil {
return err
return fmt.Errorf("failed assigning user roles. %s", err)
}
d.Partial(false)
return readUser(d, m)
Expand Down Expand Up @@ -287,7 +288,15 @@ func assignUserRoles(d *schema.ResourceData, m interface{}) error {
if len(rmRoles) > 0 {
err := api.User.RemoveRoles(d.Id(), rmRoles...)
if err != nil {
return err
// Ignore 404 errors as the role may have been deleted prior to
// unassigning them from the user.
if mErr, ok := err.(management.Error); ok {
if mErr.Status() != http.StatusNotFound {
return err
}
} else {
return err
}
}
}

Expand Down

0 comments on commit 6b3dce4

Please sign in to comment.