Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: tag delete #521

Merged
merged 13 commits into from
Aug 14, 2024
11 changes: 11 additions & 0 deletions pkg/api/tag_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
14 changes: 14 additions & 0 deletions pkg/provider/resource_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading