|
| 1 | +--- |
| 2 | +# generated by https://github.com/hashicorp/terraform-plugin-docs |
| 3 | +page_title: "elasticstack_elasticsearch_ml_datafeed_state Resource - terraform-provider-elasticstack" |
| 4 | +subcategory: "Ml" |
| 5 | +description: |- |
| 6 | + Manages the state of an existing Elasticsearch ML datafeed by starting or stopping it. This resource does not create or configure a datafeed, but instead manages the operational state of an existing datafeed. |
| 7 | + Note: Starting a non-realtime datafeed (i.e with an absolute end time) will result in the datafeed automatically stopping once all available data has been processed. By default, Terraform will restart the datafeed from the configured start time and reprocess all data again. It's recommended to ignore changes to the state attribute via the resource lifecycle https://developer.hashicorp.com/terraform/tutorials/state/resource-lifecycle#ignore-changes for non-realtime datafeeds. |
| 8 | +--- |
| 9 | + |
| 10 | +# elasticstack_elasticsearch_ml_datafeed_state (Resource) |
| 11 | + |
| 12 | +Manages the state of an existing Elasticsearch ML datafeed by starting or stopping it. This resource does not create or configure a datafeed, but instead manages the operational state of an existing datafeed. |
| 13 | + |
| 14 | +Note: Starting a non-realtime datafeed (i.e with an absolute end time) will result in the datafeed automatically stopping once all available data has been processed. By default, Terraform will restart the datafeed from the configured start time and reprocess all data again. It's recommended to ignore changes to the `state` attribute via the [resource lifecycle](https://developer.hashicorp.com/terraform/tutorials/state/resource-lifecycle#ignore-changes) for non-realtime datafeeds. |
| 15 | + |
| 16 | +## Example Usage |
| 17 | + |
| 18 | +```terraform |
| 19 | +## The following resources setup a realtime ML datafeed. |
| 20 | +resource "elasticstack_elasticsearch_index" "ml_datafeed_index" { |
| 21 | + name = "ml-datafeed-data" |
| 22 | + mappings = jsonencode({ |
| 23 | + properties = { |
| 24 | + "@timestamp" = { |
| 25 | + type = "date" |
| 26 | + } |
| 27 | + value = { |
| 28 | + type = "double" |
| 29 | + } |
| 30 | + user = { |
| 31 | + type = "keyword" |
| 32 | + } |
| 33 | + } |
| 34 | + }) |
| 35 | +} |
| 36 | +
|
| 37 | +resource "elasticstack_elasticsearch_ml_anomaly_detection_job" "example" { |
| 38 | + job_id = "example-anomaly-job" |
| 39 | + description = "Example anomaly detection job" |
| 40 | +
|
| 41 | + analysis_config { |
| 42 | + bucket_span = "15m" |
| 43 | + detectors { |
| 44 | + function = "mean" |
| 45 | + field_name = "value" |
| 46 | + by_field_name = "user" |
| 47 | + } |
| 48 | + } |
| 49 | +
|
| 50 | + data_description { |
| 51 | + time_field = "@timestamp" |
| 52 | + } |
| 53 | +} |
| 54 | +
|
| 55 | +resource "elasticstack_elasticsearch_ml_datafeed" "example" { |
| 56 | + datafeed_id = "example-datafeed" |
| 57 | + job_id = elasticstack_elasticsearch_ml_anomaly_detection_job.example.job_id |
| 58 | + indices = [elasticstack_elasticsearch_index.ml_datafeed_index.name] |
| 59 | +
|
| 60 | + query = jsonencode({ |
| 61 | + bool = { |
| 62 | + must = [ |
| 63 | + { |
| 64 | + range = { |
| 65 | + "@timestamp" = { |
| 66 | + gte = "now-7d" |
| 67 | + } |
| 68 | + } |
| 69 | + } |
| 70 | + ] |
| 71 | + } |
| 72 | + }) |
| 73 | +} |
| 74 | +
|
| 75 | +resource "elasticstack_elasticsearch_ml_datafeed_state" "example" { |
| 76 | + datafeed_id = elasticstack_elasticsearch_ml_datafeed.example.datafeed_id |
| 77 | + state = "started" |
| 78 | + force = false |
| 79 | +} |
| 80 | +
|
| 81 | +## A non-realtime datafeed will automatically stop once all data has been processed. |
| 82 | +## It's recommended to ignore changes to the `state` attribute via the resource lifecycle for such datafeeds. |
| 83 | +
|
| 84 | +resource "elasticstack_elasticsearch_ml_anomaly_detection_job" "non-realtime" { |
| 85 | + job_id = "non-realtime-anomaly-job" |
| 86 | + description = "Test job for datafeed state testing with time range" |
| 87 | + analysis_config = { |
| 88 | + bucket_span = "1h" |
| 89 | + detectors = [{ |
| 90 | + function = "count" |
| 91 | + detector_description = "count" |
| 92 | + }] |
| 93 | + } |
| 94 | + data_description = { |
| 95 | + time_field = "@timestamp" |
| 96 | + time_format = "epoch_ms" |
| 97 | + } |
| 98 | + analysis_limits = { |
| 99 | + model_memory_limit = "10mb" |
| 100 | + } |
| 101 | +} |
| 102 | +
|
| 103 | +resource "elasticstack_elasticsearch_ml_job_state" "non-realtime" { |
| 104 | + job_id = elasticstack_elasticsearch_ml_anomaly_detection_job.non-realtime.job_id |
| 105 | + state = "opened" |
| 106 | +
|
| 107 | + lifecycle { |
| 108 | + ignore_changes = ["state"] |
| 109 | + } |
| 110 | +} |
| 111 | +
|
| 112 | +resource "elasticstack_elasticsearch_ml_datafeed" "non-realtime" { |
| 113 | + datafeed_id = "non-realtime-datafeed" |
| 114 | + job_id = elasticstack_elasticsearch_ml_anomaly_detection_job.non-realtime.job_id |
| 115 | + indices = [elasticstack_elasticsearch_index.ml_datafeed_index.name] |
| 116 | + query = jsonencode({ |
| 117 | + match_all = {} |
| 118 | + }) |
| 119 | +} |
| 120 | +
|
| 121 | +resource "elasticstack_elasticsearch_ml_datafeed_state" "non-realtime" { |
| 122 | + datafeed_id = elasticstack_elasticsearch_ml_datafeed.non-realtime.datafeed_id |
| 123 | + state = "started" |
| 124 | + start = "2024-01-01T00:00:00Z" |
| 125 | + end = "2024-01-02T00:00:00Z" |
| 126 | + datafeed_timeout = "60s" |
| 127 | +
|
| 128 | + lifecycle { |
| 129 | + ignore_changes = ["state"] |
| 130 | + } |
| 131 | +} |
| 132 | +``` |
| 133 | + |
| 134 | +<!-- schema generated by tfplugindocs --> |
| 135 | +## Schema |
| 136 | + |
| 137 | +### Required |
| 138 | + |
| 139 | +- `datafeed_id` (String) Identifier for the ML datafeed. |
| 140 | +- `state` (String) The desired state for the ML datafeed. Valid values are `started` and `stopped`. |
| 141 | + |
| 142 | +### Optional |
| 143 | + |
| 144 | +- `datafeed_timeout` (String) Timeout for the operation. Examples: `30s`, `5m`, `1h`. Default is `30s`. |
| 145 | +- `elasticsearch_connection` (Block List, Deprecated) Elasticsearch connection configuration block. (see [below for nested schema](#nestedblock--elasticsearch_connection)) |
| 146 | +- `end` (String) The time that the datafeed should end collecting data. When not specified, the datafeed continues in real-time. This property must be specified in RFC 3339 format. |
| 147 | +- `force` (Boolean) When stopping a datafeed, use to forcefully stop it. |
| 148 | +- `start` (String) The time that the datafeed should start collecting data. When not specified, the datafeed starts in real-time. This property must be specified in RFC 3339 format. |
| 149 | +- `timeouts` (Attributes) (see [below for nested schema](#nestedatt--timeouts)) |
| 150 | + |
| 151 | +### Read-Only |
| 152 | + |
| 153 | +- `id` (String) Internal identifier of the resource |
| 154 | + |
| 155 | +<a id="nestedblock--elasticsearch_connection"></a> |
| 156 | +### Nested Schema for `elasticsearch_connection` |
| 157 | + |
| 158 | +Optional: |
| 159 | + |
| 160 | +- `api_key` (String, Sensitive) API Key to use for authentication to Elasticsearch |
| 161 | +- `bearer_token` (String, Sensitive) Bearer Token to use for authentication to Elasticsearch |
| 162 | +- `ca_data` (String) PEM-encoded custom Certificate Authority certificate |
| 163 | +- `ca_file` (String) Path to a custom Certificate Authority certificate |
| 164 | +- `cert_data` (String) PEM encoded certificate for client auth |
| 165 | +- `cert_file` (String) Path to a file containing the PEM encoded certificate for client auth |
| 166 | +- `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. |
| 167 | +- `es_client_authentication` (String, Sensitive) ES Client Authentication field to be used with the JWT token |
| 168 | +- `headers` (Map of String, Sensitive) A list of headers to be sent with each request to Elasticsearch. |
| 169 | +- `insecure` (Boolean) Disable TLS certificate validation |
| 170 | +- `key_data` (String, Sensitive) PEM encoded private key for client auth |
| 171 | +- `key_file` (String) Path to a file containing the PEM encoded private key for client auth |
| 172 | +- `password` (String, Sensitive) Password to use for API authentication to Elasticsearch. |
| 173 | +- `username` (String) Username to use for API authentication to Elasticsearch. |
| 174 | + |
| 175 | + |
| 176 | +<a id="nestedatt--timeouts"></a> |
| 177 | +### Nested Schema for `timeouts` |
| 178 | + |
| 179 | +Optional: |
| 180 | + |
| 181 | +- `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). |
| 182 | +- `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). |
| 183 | + |
| 184 | +## Import |
| 185 | + |
| 186 | +Import is supported using the following syntax: |
| 187 | + |
| 188 | +The [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import) can be used, for example: |
| 189 | + |
| 190 | +```shell |
| 191 | +terraform import elasticstack_elasticsearch_ml_datafeed_state.example my-datafeed-id |
| 192 | +``` |
0 commit comments