From f37816a1593f7ab4aaf5ccf0ff03b2553d4b0246 Mon Sep 17 00:00:00 2001 From: YannC Date: Tue, 3 Dec 2024 14:57:50 +0100 Subject: [PATCH] fix(namespace_file): handle trailing slash for deletion --- internal/provider/resource_namespace_file.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/internal/provider/resource_namespace_file.go b/internal/provider/resource_namespace_file.go index fda76ef..e0b172f 100644 --- a/internal/provider/resource_namespace_file.go +++ b/internal/provider/resource_namespace_file.go @@ -85,16 +85,16 @@ func resourceNamespaceFileCreate(ctx context.Context, d *schema.ResourceData, me return diag.FromErr(err) } - filename = d.Get("filename").(string) + filename = d.Get("filename").(string) - // Check if filename starts with a "/" - if !strings.HasPrefix(filename, "/") { - filename = "/" + filename - } + // Check if filename starts with a "/" + if !strings.HasPrefix(filename, "/") { + filename = "/" + filename + } - if err := d.Set("filename", filename); err != nil { - return diag.FromErr(err) - } + if err := d.Set("filename", filename); err != nil { + return diag.FromErr(err) + } if err := d.Set("content", content); err != nil { return diag.FromErr(err) @@ -153,6 +153,10 @@ func resourceNamespaceFileDelete(ctx context.Context, d *schema.ResourceData, me namespace, filename := namespaceFileConvertId(d.Id()) tenantId := c.TenantId + if !strings.HasPrefix(filename, "/") { + filename = "/" + filename + } + url := fmt.Sprintf("%s/namespaces/%s/files?path=%s", apiRoot(tenantId), namespace, filename) _, reqErr := c.request("DELETE", url, nil)