diff --git a/CHANGELOG.md b/CHANGELOG.md index 217bf420f..1e913a7c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### Added - New resource `elasticstack_elasticsearch_logstash_pipeline` to manage Logstash pipelines ([Centralized Pipeline Management](https://www.elastic.co/guide/en/logstash/current/logstash-centralized-pipeline-management.html)) ([#151](https://github.com/elastic/terraform-provider-elasticstack/pull/151)) +- Add `elasticstack_elasticsearch_script` resource ([#173](https://github.com/elastic/terraform-provider-elasticstack/pull/173)) - Add `elasticstack_elasticsearch_security_role` data source ([#177](https://github.com/elastic/terraform-provider-elasticstack/pull/177)) - Add `elasticstack_elasticsearch_security_role_mapping` data source ([#178](https://github.com/elastic/terraform-provider-elasticstack/pull/178)) diff --git a/docs/resources/elasticsearch_script.md b/docs/resources/elasticsearch_script.md new file mode 100644 index 000000000..aeb8ac094 --- /dev/null +++ b/docs/resources/elasticsearch_script.md @@ -0,0 +1,83 @@ +--- +subcategory: "Cluster" +layout: "" +page_title: "Elasticstack: elasticstack_elasticsearch_script Resource" +description: |- + Creates or updates a stored script or search template. +--- + +# Resource: elasticstack_elasticsearch_script + +Creates or updates a stored script or search template. See https://www.elastic.co/guide/en/elasticsearch/reference/current/create-stored-script-api.html + +## Example Usage + +```terraform +provider "elasticstack" { + elasticsearch {} +} + +resource "elasticstack_elasticsearch_script" "my_script" { + script_id = "my_script" + lang = "painless" + source = "Math.log(_score * 2) + params['my_modifier']" + context = "score" +} + +resource "elasticstack_elasticsearch_script" "my_search_template" { + script_id = "my_search_template" + lang = "mustache" + source = jsonencode({ + query = { + match = { + message = "{{query_string}}" + } + } + from = "{{from}}" + size = "{{size}}" + }) + params = jsonencode({ + query_string = "My query string" + }) +} +``` + + +## Schema + +### Required + +- `lang` (String) Script language. For search templates, use `mustache`. +- `script_id` (String) Identifier for the stored script. Must be unique within the cluster. +- `source` (String) For scripts, a string containing the script. For search templates, an object containing the search template. + +### Optional + +- `context` (String) Context in which the script or search template should run. +- `elasticsearch_connection` (Block List, Max: 1) Used to establish connection to Elasticsearch server. Overrides environment variables if present. (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. + + +### Nested Schema for `elasticsearch_connection` + +Optional: + +- `api_key` (String, Sensitive) API Key to use for authentication to Elasticsearch +- `ca_data` (String) PEM-encoded custom Certificate Authority certificate +- `ca_file` (String) Path to a custom Certificate Authority certificate +- `endpoints` (List of String, Sensitive) A list of endpoints the Terraform provider will point to. They must include the http(s) schema and port number. +- `insecure` (Boolean) Disable TLS certificate validation +- `password` (String, Sensitive) A password to use for API authentication to Elasticsearch. +- `username` (String) A username to use for API authentication to Elasticsearch. + +## Import + +Import is supported using the following syntax: + +```shell +terraform import elasticstack_elasticsearch_script.my_script /