From d4c2d409395c0837550f559c2082de8d3be73e68 Mon Sep 17 00:00:00 2001 From: magodo Date: Tue, 16 Apr 2024 10:38:54 +0800 Subject: [PATCH] `restful_resource` - `create_method` supports `PATCH` (#86) --- docs/data-sources/resource.md | 2 -- docs/resources/operation.md | 2 -- docs/resources/resource.md | 2 +- internal/client/client.go | 2 ++ internal/provider/resource.go | 6 +++--- 5 files changed, 6 insertions(+), 8 deletions(-) diff --git a/docs/data-sources/resource.md b/docs/data-sources/resource.md index ae5f0d0..622ed01 100644 --- a/docs/data-sources/resource.md +++ b/docs/data-sources/resource.md @@ -101,5 +101,3 @@ Required: Optional: - `pending` (List of String) The expected status sentinels for pending status. - - diff --git a/docs/resources/operation.md b/docs/resources/operation.md index e391955..fdc5c38 100644 --- a/docs/resources/operation.md +++ b/docs/resources/operation.md @@ -238,5 +238,3 @@ Required: Optional: - `pending` (List of String) The expected status sentinels for pending status. - - diff --git a/docs/resources/resource.md b/docs/resources/resource.md index 8a7a4ca..aaeaa64 100644 --- a/docs/resources/resource.md +++ b/docs/resources/resource.md @@ -46,7 +46,7 @@ resource "restful_resource" "rg" { ### Optional - `check_existance` (Boolean) Whether to check resource already existed? Defaults to `false`. -- `create_method` (String) The method used to create the resource. Possible values are `PUT` and `POST`. This overrides the `create_method` set in the provider block (defaults to POST). +- `create_method` (String) The method used to create the resource. Possible values are `PUT`, `POST` and `PATCH`. This overrides the `create_method` set in the provider block (defaults to POST). - `create_selector` (String) A selector in [gjson query syntax](https://github.com/tidwall/gjson/blob/master/SYNTAX.md#queries) query syntax, that is used when create returns a collection of resources, to select exactly one member resource of from it. By default, the whole response body is used as the body. - `delete_method` (String) The method used to delete the resource. Possible values are `DELETE` and `POST`. This overrides the `delete_method` set in the provider block (defaults to DELETE). - `delete_path` (String) The API path used to delete the resource. The `id` is used instead if `delete_path` is absent. The path can be string literal, or combined by followings: `$(path)` expanded to `path`, `$(body.x.y.z)` expands to the `x.y.z` property (urlencoded) in API body, `#(body.id)` expands to the `id` property, with `base_url` prefix trimmed. diff --git a/internal/client/client.go b/internal/client/client.go index fd3e85c..70242e7 100644 --- a/internal/client/client.go +++ b/internal/client/client.go @@ -189,6 +189,8 @@ func (c *Client) Create(ctx context.Context, path string, body interface{}, opt return req.Post(path) case "PUT": return req.Put(path) + case "PATCH": + return req.Patch(path) default: return nil, fmt.Errorf("unknown create method: %s", opt.Method) } diff --git a/internal/provider/resource.go b/internal/provider/resource.go index c7eb9b0..eb085cc 100644 --- a/internal/provider/resource.go +++ b/internal/provider/resource.go @@ -417,11 +417,11 @@ func (r *Resource) Schema(ctx context.Context, req resource.SchemaRequest, resp ElementType: types.StringType, }, "create_method": schema.StringAttribute{ - Description: "The method used to create the resource. Possible values are `PUT` and `POST`. This overrides the `create_method` set in the provider block (defaults to POST).", - MarkdownDescription: "The method used to create the resource. Possible values are `PUT` and `POST`. This overrides the `create_method` set in the provider block (defaults to POST).", + Description: "The method used to create the resource. Possible values are `PUT`, `POST` and `PATCH`. This overrides the `create_method` set in the provider block (defaults to POST).", + MarkdownDescription: "The method used to create the resource. Possible values are `PUT`, `POST` and `PATCH`. This overrides the `create_method` set in the provider block (defaults to POST).", Optional: true, Validators: []validator.String{ - stringvalidator.OneOf("PUT", "POST"), + stringvalidator.OneOf("PUT", "POST", "PATCH"), }, }, "update_method": schema.StringAttribute{