Skip to content
Open
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
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.
---

# 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]
}
43 changes: 22 additions & 21 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ require (
github.com/hashicorp/go-cty v1.5.0
github.com/hashicorp/go-uuid v1.0.3
github.com/hashicorp/go-version v1.7.0
github.com/hashicorp/terraform-plugin-framework v1.15.1
github.com/hashicorp/terraform-plugin-framework v1.16.0
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.18.0
github.com/hashicorp/terraform-plugin-go v0.28.0
github.com/hashicorp/terraform-plugin-go v0.29.0
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/hashicorp/terraform-plugin-mux v0.20.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.37.0
Expand All @@ -27,11 +28,11 @@ require (

require (
al.essio.dev/pkg/shellescape v1.6.0 // indirect
cel.dev/expr v0.22.1 // indirect
cel.dev/expr v0.24.0 // indirect
cloud.google.com/go v0.120.0 // indirect
cloud.google.com/go/auth v0.15.0 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.8 // indirect
cloud.google.com/go/compute/metadata v0.6.0 // indirect
cloud.google.com/go/compute/metadata v0.7.0 // indirect
cloud.google.com/go/iam v1.4.2 // indirect
cloud.google.com/go/kms v1.21.1 // indirect
cloud.google.com/go/longrunning v0.6.6 // indirect
Expand Down Expand Up @@ -59,7 +60,7 @@ require (
github.com/Azure/go-autorest/tracing v0.6.1 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v1.4.2 // indirect
github.com/BurntSushi/toml v1.5.0 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.27.0 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.29.0 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.51.0 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.51.0 // indirect
github.com/Kunde21/markdownfmt/v3 v3.1.0 // indirect
Expand Down Expand Up @@ -131,7 +132,7 @@ require (
github.com/charmbracelet/x/term v0.2.1 // indirect
github.com/chrismellard/docker-credential-acr-env v0.0.0-20230304212654-82a0ddb27589 // indirect
github.com/cloudflare/circl v1.6.1 // indirect
github.com/cncf/xds/go v0.0.0-20250326154945-ae57f3c0d45f // indirect
github.com/cncf/xds/go v0.0.0-20250501225837-2ac532fd4443 // indirect
github.com/containerd/stargz-snapshotter/estargz v0.16.3 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
github.com/cyberphone/json-canonicalization v0.0.0-20241213102144-19d51d7fe467 // indirect
Expand Down Expand Up @@ -170,8 +171,8 @@ require (
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.6.2 // indirect
github.com/go-git/go-git/v5 v5.14.0 // indirect
github.com/go-jose/go-jose/v4 v4.1.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-jose/go-jose/v4 v4.1.1 // indirect
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/analysis v0.23.0 // indirect
github.com/go-openapi/errors v0.22.1 // indirect
Expand Down Expand Up @@ -216,7 +217,7 @@ require (
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-hclog v1.6.3 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-plugin v1.6.3 // indirect
github.com/hashicorp/go-plugin v1.7.0 // indirect
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
github.com/hashicorp/golang-lru v1.0.2 // indirect
github.com/hashicorp/hc-install v0.9.2 // indirect
Expand All @@ -225,9 +226,9 @@ require (
github.com/hashicorp/terraform-exec v0.23.0 // indirect
github.com/hashicorp/terraform-json v0.25.0 // indirect
github.com/hashicorp/terraform-plugin-docs v0.22.0 // indirect
github.com/hashicorp/terraform-registry-address v0.2.5 // indirect
github.com/hashicorp/terraform-registry-address v0.4.0 // indirect
github.com/hashicorp/terraform-svchost v0.1.1 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/hashicorp/yamux v0.1.2 // indirect
github.com/huandu/xstrings v1.5.0 // indirect
github.com/in-toto/attestation v1.1.1 // indirect
github.com/in-toto/in-toto-golang v0.9.0 // indirect
Expand Down Expand Up @@ -361,14 +362,14 @@ require (
go.mongodb.org/mongo-driver v1.17.3 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
go.opentelemetry.io/contrib/detectors/gcp v1.35.0 // indirect
go.opentelemetry.io/contrib/detectors/gcp v1.36.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.60.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.60.0 // indirect
go.opentelemetry.io/otel v1.35.0 // indirect
go.opentelemetry.io/otel/metric v1.35.0 // indirect
go.opentelemetry.io/otel/sdk v1.35.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.35.0 // indirect
go.opentelemetry.io/otel/trace v1.35.0 // indirect
go.opentelemetry.io/otel v1.37.0 // indirect
go.opentelemetry.io/otel/metric v1.37.0 // indirect
go.opentelemetry.io/otel/sdk v1.37.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.37.0 // indirect
go.opentelemetry.io/otel/trace v1.37.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/automaxprocs v1.6.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
Expand All @@ -389,10 +390,10 @@ require (
google.golang.org/api v0.228.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20250324211829-b45e905df463 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20250409194420-de1ac958c67a // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250409194420-de1ac958c67a // indirect
google.golang.org/grpc v1.72.1 // indirect
google.golang.org/protobuf v1.36.6 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20250707201910-8d1bb00bc6a7 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250707201910-8d1bb00bc6a7 // indirect
google.golang.org/grpc v1.75.1 // indirect
google.golang.org/protobuf v1.36.9 // indirect
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
gopkg.in/mail.v2 v2.3.1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
Expand Down
Loading
Loading