From 0ccd183ba987ffcc1f23faeb6a16f8538e502944 Mon Sep 17 00:00:00 2001 From: Florian Blampey Date: Fri, 13 Oct 2023 13:47:57 +0200 Subject: [PATCH] fixes #237: handle missing resources (registry) (#378) Signed-off-by: flbla --- provider/resource_registry.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/provider/resource_registry.go b/provider/resource_registry.go index 5a10b78b..55038456 100644 --- a/provider/resource_registry.go +++ b/provider/resource_registry.go @@ -39,7 +39,7 @@ func resourceRegistry() *schema.Resource { Type: schema.TypeString, Sensitive: true, Optional: true, - Default: "", + Default: "", }, "insecure": { Type: schema.TypeBool, @@ -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) @@ -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