diff --git a/pkg/api/tag_client.go b/pkg/api/tag_client.go index 0264be45..0d5cadd4 100644 --- a/pkg/api/tag_client.go +++ b/pkg/api/tag_client.go @@ -101,3 +101,14 @@ func (tc TagClient) List(ctx context.Context) ([]api.TagResponse, error) { return response.Data, err } + +func (tc TagClient) Delete(ctx context.Context, tagId string) error { + url := fmt.Sprintf("tags/%s", tagId) + + _, err := tc.doRequest(ctx, http.MethodDelete, url, nil) + if err != nil { + return err + } + + return nil +} diff --git a/pkg/provider/resource_tag.go b/pkg/provider/resource_tag.go index 34e1b048..aafc454d 100644 --- a/pkg/provider/resource_tag.go +++ b/pkg/provider/resource_tag.go @@ -168,6 +168,20 @@ func (tr *tagResource) Update(ctx context.Context, req resource.UpdateRequest, r } func (tr *tagResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state TagResourceModel + diags := req.State.Get(ctx, &state) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + err := tr.client.Delete(ctx, state.TagId.ValueString()) + if err != nil { + if !appendDiagFromBAErr(err, &resp.Diagnostics) { + resp.Diagnostics.AddError("Error deleting tag", err.Error()) + } + return + } } func (tr *tagResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {