Skip to content

Commit

Permalink
fixes #237: handle missing resources (registry) (#378)
Browse files Browse the repository at this point in the history
Signed-off-by: flbla <[email protected]>
  • Loading branch information
flbla authored Oct 13, 2023
1 parent 1e34aed commit 0ccd183
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions provider/resource_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func resourceRegistry() *schema.Resource {
Type: schema.TypeString,
Sensitive: true,
Optional: true,
Default: "",
Default: "",
},
"insecure": {
Type: schema.TypeBool,
Expand Down Expand Up @@ -90,14 +90,16 @@ func resourceRegistryRead(d *schema.ResourceData, m interface{}) error {
resp, _, respCode, err := apiClient.SendRequest("GET", d.Id(), nil, 200)
if respCode == 404 && err != nil {
d.SetId("")
return fmt.Errorf("Resource not found %s", d.Id())
return nil
} else if err != nil {
return fmt.Errorf("resource not found %s", d.Id())
}

var jsonData models.RegistryBody
err = json.Unmarshal([]byte(resp), &jsonData)
if respCode == 404 && err != nil {
if err != nil {
d.SetId("")
return fmt.Errorf("Resource not found %s", d.Id())
return fmt.Errorf("resource not found %s", d.Id())
}

registryName, _ := client.GetRegistryType(jsonData.Type)
Expand Down Expand Up @@ -129,8 +131,8 @@ func resourceRegistryUpdate(d *schema.ResourceData, m interface{}) error {
func resourceRegistryDelete(d *schema.ResourceData, m interface{}) error {
apiClient := m.(*client.Client)

_, _, _, err := apiClient.SendRequest("DELETE", d.Id(), nil, 200)
if err != nil {
_, _, respCode, err := apiClient.SendRequest("DELETE", d.Id(), nil, 200)
if respCode != 404 && err != nil { // We can't delete something that doesn't exist. Hence the 404-check
return err
}
return nil
Expand Down

0 comments on commit 0ccd183

Please sign in to comment.