|
7 | 7 |
|
8 | 8 | "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" |
9 | 9 | "github.com/hashicorp/terraform-plugin-framework/diag" |
| 10 | + "github.com/hashicorp/terraform-plugin-framework/path" |
10 | 11 | "github.com/hashicorp/terraform-plugin-framework/resource" |
11 | 12 | "github.com/hashicorp/terraform-plugin-framework/resource/schema" |
12 | 13 | "github.com/hashicorp/terraform-plugin-framework/schema/validator" |
@@ -151,5 +152,27 @@ func (r *UserRoleResource) Update(ctx context.Context, req resource.UpdateReques |
151 | 152 | } |
152 | 153 |
|
153 | 154 | func (r *UserRoleResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { |
154 | | - resp.Diagnostics.AddWarning("Delete not supported", "This resource does not support deletion.") |
| 155 | + var data UserRoleResourceModel |
| 156 | + |
| 157 | + resp.Diagnostics.Append(req.State.Get(ctx, &data)...) |
| 158 | + if resp.Diagnostics.HasError() { |
| 159 | + return |
| 160 | + } |
| 161 | + |
| 162 | + httpResp, err := r.client.DeleteUserWithResponse( |
| 163 | + ctx, |
| 164 | + data.UserId.ValueString(), |
| 165 | + ) |
| 166 | + |
| 167 | + if err != nil { |
| 168 | + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to delete, got error: %s", err)) |
| 169 | + return |
| 170 | + } else if httpResp.StatusCode() != http.StatusOK { |
| 171 | + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to delete, got status code %d: %s", httpResp.StatusCode(), string(httpResp.Body))) |
| 172 | + return |
| 173 | + } |
| 174 | +} |
| 175 | + |
| 176 | +func (r *UserRoleResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { |
| 177 | + resource.ImportStatePassthroughID(ctx, path.Root("user_id"), req, resp) |
155 | 178 | } |
0 commit comments