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
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ELASTICSEARCH_CONTAINER_NAME=terraform-elasticstack-es
ELASTICSEARCH_PASSWORD=password
ELASTICSEARCH_PORT=9200
ELASTICSEARCH_URL=http://localhost:${ELASTICSEARCH_PORT}
ELASTICSEARCH_JAVA_OPTS="-Xms128m -Xmx2g"
ELASTICSEARCH_JAVA_OPTS="-Xms128m -Xmx1g"
KIBANA_CONTAINER_NAME=terraform-elasticstack-kb
KIBANA_SETTINGS_CONTAINER_NAME=terraform-elasticstack-kb-settings
FLEET_SETTINGS_CONTAINER_NAME=terraform-elasticstack-fleet-settings
Expand Down
145 changes: 145 additions & 0 deletions docs/resources/elasticsearch_ml_job_state.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
---
page_title: "elasticstack_elasticsearch_ml_job_state Resource - terraform-provider-elasticstack"
subcategory: ""
description: |-
ML Job State Resource
Manages the state of an Elasticsearch Machine Learning (ML) job, allowing you to open or close ML jobs.
This resource uses the following Elasticsearch APIs:
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
Important Notes
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: For some reason there aren't any spaces after periods in this snippet.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure where this frontmatter description is used, but the formatting is stripped here in all the docs. In this case, it looks like the result for stripping a markdown list back to plain text.

---

# elasticstack_elasticsearch_ml_job_state (Resource)

# ML Job State Resource

Manages the state of an Elasticsearch Machine Learning (ML) job, allowing you to open or close ML jobs.

This resource uses the following Elasticsearch APIs:
- [Open ML Job API](https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-open-job.html)
- [Close ML Job API](https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-close-job.html)
- [Get ML Job Stats API](https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-job-stats.html)

## Important Notes

- 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.

## Example Usage

```terraform
provider "elasticstack" {
elasticsearch {}
}
# First create an ML anomaly detection job
resource "elasticstack_elasticsearch_ml_anomaly_detector" "example" {
job_id = "example-ml-job"
description = "Example anomaly detection job"
analysis_config = {
bucket_span = "15m"
detectors = [
{
function = "count"
detector_description = "Count detector"
}
]
}
data_description = {
time_field = "@timestamp"
time_format = "epoch_ms"
}
}
# Manage the state of the ML job - open it
resource "elasticstack_elasticsearch_ml_job_state" "example" {
job_id = elasticstack_elasticsearch_ml_anomaly_detector.example.job_id
state = "opened"
# Optional settings
force = false
job_timeout = "30s"
# Timeouts for asynchronous operations
timeouts {
create = "5m"
update = "5m"
}
depends_on = [elasticstack_elasticsearch_ml_anomaly_detector.example]
}
# Example with different configuration options
resource "elasticstack_elasticsearch_ml_job_state" "example_with_options" {
job_id = elasticstack_elasticsearch_ml_anomaly_detector.example.job_id
state = "closed"
# Use force close for quicker shutdown
force = true
# Custom timeout
job_timeout = "2m"
# Custom timeouts for asynchronous operations
timeouts {
create = "10m"
update = "3m"
}
depends_on = [elasticstack_elasticsearch_ml_anomaly_detector.example]
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `job_id` (String) Identifier for the anomaly detection job.
- `state` (String) The desired state for the ML job. Valid values are `opened` and `closed`.

### Optional

- `elasticsearch_connection` (Block List, Deprecated) Elasticsearch connection configuration block. (see [below for nested schema](#nestedblock--elasticsearch_connection))
- `force` (Boolean) When closing a job, use to forcefully close it. This method is quicker but can miss important clean up tasks.
- `job_timeout` (String) Timeout for the operation. Examples: `30s`, `5m`, `1h`. Default is `30s`.
- `timeouts` (Attributes) (see [below for nested schema](#nestedatt--timeouts))

### Read-Only

- `id` (String) Internal identifier of the resource

<a id="nestedblock--elasticsearch_connection"></a>
### Nested Schema for `elasticsearch_connection`

Optional:

- `api_key` (String, Sensitive) API Key to use for authentication to Elasticsearch
- `bearer_token` (String, Sensitive) Bearer Token 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
- `cert_data` (String) PEM encoded certificate for client auth
- `cert_file` (String) Path to a file containing the PEM encoded certificate for client auth
- `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.
- `es_client_authentication` (String, Sensitive) ES Client Authentication field to be used with the JWT token
- `headers` (Map of String, Sensitive) A list of headers to be sent with each request to Elasticsearch.
- `insecure` (Boolean) Disable TLS certificate validation
- `key_data` (String, Sensitive) PEM encoded private key for client auth
- `key_file` (String) Path to a file containing the PEM encoded private key for client auth
- `password` (String, Sensitive) Password to use for API authentication to Elasticsearch.
- `username` (String) Username to use for API authentication to Elasticsearch.


<a id="nestedatt--timeouts"></a>
### Nested Schema for `timeouts`

Optional:

- `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).
- `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).
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
provider "elasticstack" {
elasticsearch {}
}

# First create an ML anomaly detection job
resource "elasticstack_elasticsearch_ml_anomaly_detector" "example" {
job_id = "example-ml-job"
description = "Example anomaly detection job"

analysis_config = {
bucket_span = "15m"
detectors = [
{
function = "count"
detector_description = "Count detector"
}
]
}

data_description = {
time_field = "@timestamp"
time_format = "epoch_ms"
}
}

# Manage the state of the ML job - open it
resource "elasticstack_elasticsearch_ml_job_state" "example" {
job_id = elasticstack_elasticsearch_ml_anomaly_detector.example.job_id
state = "opened"

# Optional settings
force = false
job_timeout = "30s"

# Timeouts for asynchronous operations
timeouts {
create = "5m"
update = "5m"
}

depends_on = [elasticstack_elasticsearch_ml_anomaly_detector.example]
}

# Example with different configuration options
resource "elasticstack_elasticsearch_ml_job_state" "example_with_options" {
job_id = elasticstack_elasticsearch_ml_anomaly_detector.example.job_id
state = "closed"

# Use force close for quicker shutdown
force = true

# Custom timeout
job_timeout = "2m"

# Custom timeouts for asynchronous operations
timeouts {
create = "10m"
update = "3m"
}

depends_on = [elasticstack_elasticsearch_ml_anomaly_detector.example]
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/hashicorp/go-version v1.7.0
github.com/hashicorp/terraform-plugin-framework v1.16.1
github.com/hashicorp/terraform-plugin-framework-jsontypes v0.2.0
github.com/hashicorp/terraform-plugin-framework-timeouts v0.6.0
github.com/hashicorp/terraform-plugin-framework-validators v0.19.0
github.com/hashicorp/terraform-plugin-go v0.29.0
github.com/hashicorp/terraform-plugin-log v0.9.0
Expand Down
7 changes: 3 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,6 @@ github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97
github.com/evanphx/json-patch/v5 v5.9.11 h1:/8HVnzMq13/3x9TPvjG08wUGqBTmZBsCWzjTM0wiaDU=
github.com/evanphx/json-patch/v5 v5.9.11/go.mod h1:3j+LviiESTElxA4p3EMKAB9HXj3/XEtnUf6OZxqIQTM=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=
github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI=
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
github.com/fatih/set v0.2.1 h1:nn2CaJyknWE/6txyUDGwysr3G5QC6xWB/PtVjPBbeaA=
Expand Down Expand Up @@ -617,6 +615,8 @@ github.com/hashicorp/terraform-plugin-framework v1.16.1 h1:1+zwFm3MEqd/0K3YBB2v9
github.com/hashicorp/terraform-plugin-framework v1.16.1/go.mod h1:0xFOxLy5lRzDTayc4dzK/FakIgBhNf/lC4499R9cV4Y=
github.com/hashicorp/terraform-plugin-framework-jsontypes v0.2.0 h1:SJXL5FfJJm17554Kpt9jFXngdM6fXbnUnZ6iT2IeiYA=
github.com/hashicorp/terraform-plugin-framework-jsontypes v0.2.0/go.mod h1:p0phD0IYhsu9bR4+6OetVvvH59I6LwjXGnTVEr8ox6E=
github.com/hashicorp/terraform-plugin-framework-timeouts v0.6.0 h1:Vv16e7EW4nT9668IV0RhdpEmnLl0im7BZx6J+QMlUkg=
github.com/hashicorp/terraform-plugin-framework-timeouts v0.6.0/go.mod h1:rpHo9hZLn4vEkvNL5xsSdLRdaDZKSinuc0xL+BdOpVA=
github.com/hashicorp/terraform-plugin-framework-validators v0.19.0 h1:Zz3iGgzxe/1XBkooZCewS0nJAaCFPFPHdNJd8FgE4Ow=
github.com/hashicorp/terraform-plugin-framework-validators v0.19.0/go.mod h1:GBKTNGbGVJohU03dZ7U8wHqc2zYnMUawgCN+gC0itLc=
github.com/hashicorp/terraform-plugin-go v0.29.0 h1:1nXKl/nSpaYIUBU1IG/EsDOX0vv+9JxAltQyDMpq5mU=
Expand Down Expand Up @@ -1377,9 +1377,8 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools/gotestsum v1.13.0 h1:+Lh454O9mu9AMG1APV4o0y7oDYKyik/3kBOiCqiEpRo=
gotest.tools/gotestsum v1.13.0/go.mod h1:7f0NS5hFb0dWr4NtcsAsF0y1kzjEFfAil0HiBQJE03Q=
gotest.tools/v3 v3.0.3 h1:4AuOwCGf4lLR9u3YOe2awrHygurzhO/HeQ6laiA6Sx0=
gotest.tools/v3 v3.0.3/go.mod h1:Z7Lb0S5l+klDB31fvDQX8ss/FlKDxtlFlw3Oa8Ymbl8=
gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=
gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
Expand Down
Loading