Skip to content

Commit

Permalink
restful_resource - create_method supports PATCH (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
magodo authored Apr 16, 2024
1 parent 3a3175d commit d4c2d40
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 8 deletions.
2 changes: 0 additions & 2 deletions docs/data-sources/resource.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,3 @@ Required:
Optional:

- `pending` (List of String) The expected status sentinels for pending status.


2 changes: 0 additions & 2 deletions docs/resources/operation.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,5 +238,3 @@ Required:
Optional:

- `pending` (List of String) The expected status sentinels for pending status.


2 changes: 1 addition & 1 deletion docs/resources/resource.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/provider/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit d4c2d40

Please sign in to comment.