|
| 1 | +--- |
| 2 | +page_title: "elasticstack_elasticsearch_ml_job_state Resource - terraform-provider-elasticstack" |
| 3 | +subcategory: "" |
| 4 | +description: |- |
| 5 | + ML Job State Resource |
| 6 | + Manages the state of an Elasticsearch Machine Learning (ML) job, allowing you to open or close ML jobs. |
| 7 | + This resource uses the following Elasticsearch APIs: |
| 8 | + Open ML Job API https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-open-job.htmlClose ML Job API https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-close-job.htmlGet ML Job Stats API https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-job-stats.html |
| 9 | + Important Notes |
| 10 | + This resource manages the state of an existing ML job, not the job configuration itself.The ML job must already exist before using this resource.Opening a job allows it to receive and process data.Closing a job stops data processing and frees up resources.Jobs can be opened and closed multiple times throughout their lifecycle. |
| 11 | +--- |
| 12 | + |
| 13 | +# elasticstack_elasticsearch_ml_job_state (Resource) |
| 14 | + |
| 15 | +# ML Job State Resource |
| 16 | + |
| 17 | +Manages the state of an Elasticsearch Machine Learning (ML) job, allowing you to open or close ML jobs. |
| 18 | + |
| 19 | +This resource uses the following Elasticsearch APIs: |
| 20 | +- [Open ML Job API](https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-open-job.html) |
| 21 | +- [Close ML Job API](https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-close-job.html) |
| 22 | +- [Get ML Job Stats API](https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-job-stats.html) |
| 23 | + |
| 24 | +## Important Notes |
| 25 | + |
| 26 | +- This resource manages the **state** of an existing ML job, not the job configuration itself. |
| 27 | +- The ML job must already exist before using this resource. |
| 28 | +- Opening a job allows it to receive and process data. |
| 29 | +- Closing a job stops data processing and frees up resources. |
| 30 | +- Jobs can be opened and closed multiple times throughout their lifecycle. |
| 31 | + |
| 32 | +## Example Usage |
| 33 | + |
| 34 | +```terraform |
| 35 | +provider "elasticstack" { |
| 36 | + elasticsearch {} |
| 37 | +} |
| 38 | +
|
| 39 | +# First create an ML anomaly detection job |
| 40 | +resource "elasticstack_elasticsearch_ml_anomaly_detector" "example" { |
| 41 | + job_id = "example-ml-job" |
| 42 | + description = "Example anomaly detection job" |
| 43 | +
|
| 44 | + analysis_config = { |
| 45 | + bucket_span = "15m" |
| 46 | + detectors = [ |
| 47 | + { |
| 48 | + function = "count" |
| 49 | + detector_description = "Count detector" |
| 50 | + } |
| 51 | + ] |
| 52 | + } |
| 53 | +
|
| 54 | + data_description = { |
| 55 | + time_field = "@timestamp" |
| 56 | + time_format = "epoch_ms" |
| 57 | + } |
| 58 | +} |
| 59 | +
|
| 60 | +# Manage the state of the ML job - open it |
| 61 | +resource "elasticstack_elasticsearch_ml_job_state" "example" { |
| 62 | + job_id = elasticstack_elasticsearch_ml_anomaly_detector.example.job_id |
| 63 | + state = "opened" |
| 64 | +
|
| 65 | + # Optional settings |
| 66 | + force = false |
| 67 | + job_timeout = "30s" |
| 68 | +
|
| 69 | + # Timeouts for asynchronous operations |
| 70 | + timeouts { |
| 71 | + create = "5m" |
| 72 | + update = "5m" |
| 73 | + } |
| 74 | +
|
| 75 | + depends_on = [elasticstack_elasticsearch_ml_anomaly_detector.example] |
| 76 | +} |
| 77 | +
|
| 78 | +# Example with different configuration options |
| 79 | +resource "elasticstack_elasticsearch_ml_job_state" "example_with_options" { |
| 80 | + job_id = elasticstack_elasticsearch_ml_anomaly_detector.example.job_id |
| 81 | + state = "closed" |
| 82 | +
|
| 83 | + # Use force close for quicker shutdown |
| 84 | + force = true |
| 85 | +
|
| 86 | + # Custom timeout |
| 87 | + job_timeout = "2m" |
| 88 | +
|
| 89 | + # Custom timeouts for asynchronous operations |
| 90 | + timeouts { |
| 91 | + create = "10m" |
| 92 | + update = "3m" |
| 93 | + } |
| 94 | +
|
| 95 | + depends_on = [elasticstack_elasticsearch_ml_anomaly_detector.example] |
| 96 | +} |
| 97 | +``` |
| 98 | + |
| 99 | +<!-- schema generated by tfplugindocs --> |
| 100 | +## Schema |
| 101 | + |
| 102 | +### Required |
| 103 | + |
| 104 | +- `job_id` (String) Identifier for the anomaly detection job. |
| 105 | +- `state` (String) The desired state for the ML job. Valid values are `opened` and `closed`. |
| 106 | + |
| 107 | +### Optional |
| 108 | + |
| 109 | +- `elasticsearch_connection` (Block List, Deprecated) Elasticsearch connection configuration block. (see [below for nested schema](#nestedblock--elasticsearch_connection)) |
| 110 | +- `force` (Boolean) When closing a job, use to forcefully close it. This method is quicker but can miss important clean up tasks. |
| 111 | +- `job_timeout` (String) Timeout for the operation. Examples: `30s`, `5m`, `1h`. Default is `30s`. |
| 112 | +- `timeouts` (Attributes) (see [below for nested schema](#nestedatt--timeouts)) |
| 113 | + |
| 114 | +### Read-Only |
| 115 | + |
| 116 | +- `id` (String) Internal identifier of the resource |
| 117 | + |
| 118 | +<a id="nestedblock--elasticsearch_connection"></a> |
| 119 | +### Nested Schema for `elasticsearch_connection` |
| 120 | + |
| 121 | +Optional: |
| 122 | + |
| 123 | +- `api_key` (String, Sensitive) API Key to use for authentication to Elasticsearch |
| 124 | +- `bearer_token` (String, Sensitive) Bearer Token to use for authentication to Elasticsearch |
| 125 | +- `ca_data` (String) PEM-encoded custom Certificate Authority certificate |
| 126 | +- `ca_file` (String) Path to a custom Certificate Authority certificate |
| 127 | +- `cert_data` (String) PEM encoded certificate for client auth |
| 128 | +- `cert_file` (String) Path to a file containing the PEM encoded certificate for client auth |
| 129 | +- `endpoints` (List of String, Sensitive) A list of endpoints where the terraform provider will point to, this must include the http(s) schema and port number. |
| 130 | +- `es_client_authentication` (String, Sensitive) ES Client Authentication field to be used with the JWT token |
| 131 | +- `headers` (Map of String, Sensitive) A list of headers to be sent with each request to Elasticsearch. |
| 132 | +- `insecure` (Boolean) Disable TLS certificate validation |
| 133 | +- `key_data` (String, Sensitive) PEM encoded private key for client auth |
| 134 | +- `key_file` (String) Path to a file containing the PEM encoded private key for client auth |
| 135 | +- `password` (String, Sensitive) Password to use for API authentication to Elasticsearch. |
| 136 | +- `username` (String) Username to use for API authentication to Elasticsearch. |
| 137 | + |
| 138 | + |
| 139 | +<a id="nestedatt--timeouts"></a> |
| 140 | +### Nested Schema for `timeouts` |
| 141 | + |
| 142 | +Optional: |
| 143 | + |
| 144 | +- `create` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours). |
| 145 | +- `update` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours). |
0 commit comments