Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- Migrate `elasticstack_kibana_action_connector` to the Terraform plugin framework ([#1269](https://github.com/elastic/terraform-provider-elasticstack/pull/1269))
- Migrate `elasticstack_elasticsearch_security_role_mapping` resource and data source to Terraform Plugin Framework ([#1279](https://github.com/elastic/terraform-provider-elasticstack/pull/1279))
- Add support for `inactivity_timeout` in `elasticstack_fleet_agent_policy` ([#641](https://github.com/elastic/terraform-provider-elasticstack/issues/641))
- Migrate `elasticstack_elasticsearch_script` resource to Terraform Plugin Framework ([#1297](https://github.com/elastic/terraform-provider-elasticstack/pull/1297))
- Add support for `kafka` output types in `elasticstack_fleet_output` ([#1302](https://github.com/elastic/terraform-provider-elasticstack/pull/1302))
- Add support for `prevent_initial_backfill` to `elasticstack_kibana_slo` ([#1071](https://github.com/elastic/terraform-provider-elasticstack/pull/1071))
- [Refactor] Regenerate the SLO client using the current OpenAPI spec ([#1303](https://github.com/elastic/terraform-provider-elasticstack/pull/1303))
Expand Down
4 changes: 2 additions & 2 deletions docs/resources/elasticsearch_script.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ resource "elasticstack_elasticsearch_script" "my_search_template" {
### Optional

- `context` (String) Context in which the script or search template should run.
- `elasticsearch_connection` (Block List, Max: 1, Deprecated) Elasticsearch connection configuration block. This property will be removed in a future provider version. Configure the Elasticsearch connection via the provider configuration instead. (see [below for nested schema](#nestedblock--elasticsearch_connection))
- `elasticsearch_connection` (Block List, Deprecated) Elasticsearch connection configuration block. (see [below for nested schema](#nestedblock--elasticsearch_connection))
- `params` (String) Parameters for the script or search template.

### Read-Only

- `id` (String) The ID of this resource.
- `id` (String) Internal identifier of the resource

<a id="nestedblock--elasticsearch_connection"></a>
### Nested Schema for `elasticsearch_connection`
Expand Down
4 changes: 2 additions & 2 deletions docs/resources/elasticsearch_watch.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
page_title: "elasticstack_elasticsearch_watch Resource - terraform-provider-elasticstack"
subcategory: "Elasticsearch"
description: |-
Manage Watches. See, https://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api.html
Manage Watches. See the Watcher API documentation https://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api.html for more details.
---

# elasticstack_elasticsearch_watch (Resource)

Manage Watches. See, https://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api.html
Manage Watches. See the [Watcher API documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api.html) for more details.

## Example Usage

Expand Down
29 changes: 15 additions & 14 deletions internal/clients/elasticsearch/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/elastic/terraform-provider-elasticstack/internal/clients"
"github.com/elastic/terraform-provider-elasticstack/internal/diagutil"
"github.com/elastic/terraform-provider-elasticstack/internal/models"
fwdiag "github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
)

Expand Down Expand Up @@ -234,68 +235,68 @@ func GetSettings(ctx context.Context, apiClient *clients.ApiClient) (map[string]
return clusterSettings, diags
}

func GetScript(ctx context.Context, apiClient *clients.ApiClient, id string) (*models.Script, diag.Diagnostics) {
func GetScript(ctx context.Context, apiClient *clients.ApiClient, id string) (*models.Script, fwdiag.Diagnostics) {
esClient, err := apiClient.GetESClient()
if err != nil {
return nil, diag.FromErr(err)
return nil, fwdiag.Diagnostics{fwdiag.NewErrorDiagnostic("Failed to get ES client", err.Error())}
}
res, err := esClient.GetScript(id, esClient.GetScript.WithContext(ctx))
if err != nil {
return nil, diag.FromErr(err)
return nil, fwdiag.Diagnostics{fwdiag.NewErrorDiagnostic("Failed to get script", err.Error())}
}
defer res.Body.Close()
if res.StatusCode == http.StatusNotFound {
return nil, nil
}
if diags := diagutil.CheckError(res, fmt.Sprintf("Unable to get stored script: %s", id)); diags.HasError() {
if diags := diagutil.CheckErrorFromFW(res, fmt.Sprintf("Unable to get stored script: %s", id)); diags.HasError() {
return nil, diags
}
var scriptResponse struct {
Script *models.Script `json:"script"`
}
if err := json.NewDecoder(res.Body).Decode(&scriptResponse); err != nil {
return nil, diag.FromErr(err)
return nil, fwdiag.Diagnostics{fwdiag.NewErrorDiagnostic("Failed to decode script response", err.Error())}
}

return scriptResponse.Script, nil
}

func PutScript(ctx context.Context, apiClient *clients.ApiClient, script *models.Script) diag.Diagnostics {
func PutScript(ctx context.Context, apiClient *clients.ApiClient, script *models.Script) fwdiag.Diagnostics {
req := struct {
Script *models.Script `json:"script"`
}{
script,
}
scriptBytes, err := json.Marshal(req)
if err != nil {
return diag.FromErr(err)
return fwdiag.Diagnostics{fwdiag.NewErrorDiagnostic("Failed to marshal script", err.Error())}
}
esClient, err := apiClient.GetESClient()
if err != nil {
return diag.FromErr(err)
return fwdiag.Diagnostics{fwdiag.NewErrorDiagnostic("Failed to get ES client", err.Error())}
}
res, err := esClient.PutScript(script.ID, bytes.NewReader(scriptBytes), esClient.PutScript.WithContext(ctx), esClient.PutScript.WithScriptContext(script.Context))
if err != nil {
return diag.FromErr(err)
return fwdiag.Diagnostics{fwdiag.NewErrorDiagnostic("Failed to put script", err.Error())}
}
defer res.Body.Close()
if diags := diagutil.CheckError(res, "Unable to put stored script"); diags.HasError() {
if diags := diagutil.CheckErrorFromFW(res, "Unable to put stored script"); diags.HasError() {
return diags
}
return nil
}

func DeleteScript(ctx context.Context, apiClient *clients.ApiClient, id string) diag.Diagnostics {
func DeleteScript(ctx context.Context, apiClient *clients.ApiClient, id string) fwdiag.Diagnostics {
esClient, err := apiClient.GetESClient()
if err != nil {
return diag.FromErr(err)
return fwdiag.Diagnostics{fwdiag.NewErrorDiagnostic("Failed to get ES client", err.Error())}
}
res, err := esClient.DeleteScript(id, esClient.DeleteScript.WithContext(ctx))
if err != nil {
return diag.FromErr(err)
return fwdiag.Diagnostics{fwdiag.NewErrorDiagnostic("Failed to delete script", err.Error())}
}
defer res.Body.Close()
if diags := diagutil.CheckError(res, fmt.Sprintf("Unable to delete script: %s", id)); diags.HasError() {
if diags := diagutil.CheckErrorFromFW(res, fmt.Sprintf("Unable to delete script: %s", id)); diags.HasError() {
return diags
}
return nil
Expand Down
151 changes: 0 additions & 151 deletions internal/elasticsearch/cluster/script.go

This file was deleted.

Loading
Loading