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

restful_resource - create_method supports PATCH #86

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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