Skip to content

Commit

Permalink
Add 404 checking to group exists
Browse files Browse the repository at this point in the history
  • Loading branch information
jamestoyer committed Dec 1, 2021
1 parent 289d35a commit b2e18a6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/artifactory/resource_artifactory_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package artifactory

import (
"fmt"
"net/http"

"github.com/go-resty/resty/v2"

Expand Down Expand Up @@ -197,7 +198,12 @@ func resourceGroupExists(d *schema.ResourceData, m interface{}) (bool, error) {
}

func groupExists(client *resty.Client, groupName string) (bool, error) {
_, err := client.R().Head(groupsEndpoint + groupName)
resp, err := client.R().Head(groupsEndpoint + groupName)
if err != nil && resp != nil && resp.StatusCode() == http.StatusNotFound {
// Do not error on 404s as this causes errors when the upstream user has been manually removed
return false, nil
}

return err == nil, err
}

Expand Down

0 comments on commit b2e18a6

Please sign in to comment.