Skip to content

Commit

Permalink
refactor(invitations): do not fail on User patch StatusForrbidden as …
Browse files Browse the repository at this point in the history
…it would require Admin permissions

Closes hashicorp#885
  • Loading branch information
bufferoverflow committed Apr 19, 2023
1 parent 51f4573 commit 12c9dad
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions internal/services/invitations/invitation_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ func invitationResourceCreate(ctx context.Context, d *schema.ResourceData, meta
if status == http.StatusNotFound {
return tf.ErrorDiagF(err, "Timed out whilst waiting for new guest user to be replicated in Azure AD")
}
return tf.ErrorDiagF(err, "Failed to patch guest user after creating invitation")
if status != http.StatusForbidden {
return tf.ErrorDiagF(err, "Failed to patch guest user after creating invitation")
}
}
status, err = usersClient.Update(ctx, msgraph.User{
DirectoryObject: msgraph.DirectoryObject{
Expand All @@ -186,7 +188,9 @@ func invitationResourceCreate(ctx context.Context, d *schema.ResourceData, meta
if status == http.StatusNotFound {
return tf.ErrorDiagF(err, "Timed out whilst waiting for new guest user to be replicated in Azure AD")
}
return tf.ErrorDiagF(err, "Failed to patch guest user after creating invitation")
if status != http.StatusForbidden {
return tf.ErrorDiagF(err, "Failed to patch guest user after creating invitation")
}
}

return invitationResourceRead(ctx, d, meta)
Expand Down Expand Up @@ -228,6 +232,12 @@ func invitationResourceDelete(ctx context.Context, d *schema.ResourceData, meta
}

status, err = client.Delete(ctx, userID)

// Only people with User.ReadWrite.All or Directory.ReadWrite.All can delete users
if status == http.StatusForbidden {
return nil
}

if err != nil {
return tf.ErrorDiagPathF(err, "id", "Deleting invited user with object ID %q, got status %d with error: %+v", userID, status, err)
}
Expand Down

0 comments on commit 12c9dad

Please sign in to comment.