Skip to content

Commit

Permalink
add delete functionality for user resource
Browse files Browse the repository at this point in the history
  • Loading branch information
Luiggi33 committed Jul 25, 2024
1 parent e7af332 commit 43c18ad
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions internal/provider/user_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,23 @@ func (r *userResource) Update(ctx context.Context, req resource.UpdateRequest, r

// Delete deletes the resource and removes the Terraform state on success.
func (r *userResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
// Retrieve values from state
var state userResourceModel
diags := req.State.Get(ctx, &state)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}

// Delete existing user
err := r.client.DeleteUser(int(state.ID.ValueInt64()))
if err != nil {
resp.Diagnostics.AddError(
"Error Deleting Pterodactyl User",
"Could not delete user, unexpected error: "+err.Error(),
)
return
}
}

// Configure adds the provider configured client to the resource.
Expand Down

0 comments on commit 43c18ad

Please sign in to comment.