Skip to content

Commit 79fbc8a

Browse files
committed
Merge branch 'main' of github.com:togish/terraform-provider-elasticstack into indextemplate-component-ignore-missing
2 parents f8c7073 + 68dfcdd commit 79fbc8a

File tree

21 files changed

+585
-27
lines changed

21 files changed

+585
-27
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
## [Unreleased]
22

33
- Add support for `timeslice_metric_indicator` in `elasticstack_kibana_slo` ([#1195](https://github.com/elastic/terraform-provider-elasticstack/pull/1195))
4+
- Add `elasticstack_elasticsearch_ingest_processor_reroute` data source ([#678](https://github.com/elastic/terraform-provider-elasticstack/issues/678))
5+
- Add support for `supports_agentless` to `elasticstack_fleet_agent_policy` ([#1197](https://github.com/elastic/terraform-provider-elasticstack/pull/1197))
6+
- Ignore `master_timeout` when targeting Serverless projects ([#1207](https://github.com/elastic/terraform-provider-elasticstack/pull/1207))
47
- Add `ignore_missing_component_templates` to `elasticstack_elasticsearch_index_template` ([#1206](https://github.com/elastic/terraform-provider-elasticstack/pull/1206))
58

69
## [0.11.16] - 2025-07-09
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
subcategory: "Ingest"
3+
layout: ""
4+
page_title: "Elasticstack: elasticstack_elasticsearch_ingest_processor_reroute Data Source"
5+
description: |-
6+
Helper data source to create a processor which reroutes a document to a different data stream, index, or index alias.
7+
---
8+
9+
# Data Source: elasticstack_elasticsearch_ingest_processor_reroute
10+
11+
Reroutes a document to a different data stream, index, or index alias. This processor is useful for routing documents based on data stream routing rules.
12+
13+
See: https://www.elastic.co/guide/en/elasticsearch/reference/current/reroute-processor.html
14+
15+
16+
## Example Usage
17+
18+
```terraform
19+
provider "elasticstack" {
20+
elasticsearch {}
21+
}
22+
23+
data "elasticstack_elasticsearch_ingest_processor_reroute" "reroute" {
24+
destination = "logs-generic-default"
25+
dataset = "generic"
26+
namespace = "default"
27+
}
28+
29+
resource "elasticstack_elasticsearch_ingest_pipeline" "my_ingest_pipeline" {
30+
name = "reroute-ingest"
31+
32+
processors = [
33+
data.elasticstack_elasticsearch_ingest_processor_reroute.reroute.json
34+
]
35+
}
36+
```
37+
38+
<!-- schema generated by tfplugindocs -->
39+
## Schema
40+
41+
### Optional
42+
43+
- `dataset` (String) The destination dataset to route the document to.
44+
- `description` (String) Description of the processor.
45+
- `destination` (String) The destination data stream, index, or index alias to route the document to.
46+
- `if` (String) Conditionally execute the processor
47+
- `ignore_failure` (Boolean) Ignore failures for the processor.
48+
- `namespace` (String) The destination namespace to route the document to.
49+
- `on_failure` (List of String) Handle failures for the processor.
50+
- `tag` (String) Identifier for the processor.
51+
52+
### Read-Only
53+
54+
- `id` (String) Internal identifier of the resource.
55+
- `json` (String) JSON representation of this data source.

docs/resources/fleet_agent_policy.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ resource "elasticstack_fleet_agent_policy" "test_policy" {
5656
- `monitoring_output_id` (String) The identifier for monitoring output.
5757
- `policy_id` (String) Unique identifier of the agent policy.
5858
- `skip_destroy` (Boolean) Set to true if you do not wish the agent policy to be deleted at destroy time, and instead just remove the agent policy from the Terraform state.
59+
- `supports_agentless` (Boolean) Set to true to enable agentless data collection.
5960
- `sys_monitoring` (Boolean) Enable collection of system logs and metrics.
6061

6162
### Read-Only
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
provider "elasticstack" {
2+
elasticsearch {}
3+
}
4+
5+
data "elasticstack_elasticsearch_ingest_processor_reroute" "reroute" {
6+
destination = "logs-generic-default"
7+
dataset = "generic"
8+
namespace = "default"
9+
}
10+
11+
resource "elasticstack_elasticsearch_ingest_pipeline" "my_ingest_pipeline" {
12+
name = "reroute-ingest"
13+
14+
processors = [
15+
data.elasticstack_elasticsearch_ingest_processor_reroute.reroute.json
16+
]
17+
}

internal/clients/api_client.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ type CompositeId struct {
3333
ResourceId string
3434
}
3535

36+
const ServerlessFlavor = "serverless"
37+
3638
func CompositeIdFromStr(id string) (*CompositeId, diag.Diagnostics) {
3739
var diags diag.Diagnostics
3840
idParts := strings.Split(id, "/")
@@ -352,6 +354,24 @@ func (a *ApiClient) serverInfo(ctx context.Context) (*models.ClusterInfo, diag.D
352354
return &info, diags
353355
}
354356

357+
func (a *ApiClient) EnforceMinVersion(ctx context.Context, minVersion *version.Version) (bool, diag.Diagnostics) {
358+
flavor, diags := a.ServerFlavor(ctx)
359+
if diags.HasError() {
360+
return false, diags
361+
}
362+
363+
if flavor == ServerlessFlavor {
364+
return true, nil
365+
}
366+
367+
serverVersion, diags := a.ServerVersion(ctx)
368+
if diags.HasError() {
369+
return false, diags
370+
}
371+
372+
return serverVersion.GreaterThanOrEqual(minVersion), nil
373+
}
374+
355375
func (a *ApiClient) ServerVersion(ctx context.Context) (*version.Version, diag.Diagnostics) {
356376
if a.elasticsearch != nil {
357377
return a.versionFromElasticsearch(ctx)

internal/elasticsearch/index/index/models.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,11 @@ func (model tfModel) toPutIndexParams(serverFlavor string) models.PutIndexParams
286286
timeout, _ := model.Timeout.Parse()
287287

288288
params := models.PutIndexParams{
289-
MasterTimeout: masterTimeout,
290-
Timeout: timeout,
289+
Timeout: timeout,
291290
}
292291

293-
if serverFlavor != "serverless" {
292+
if serverFlavor != clients.ServerlessFlavor {
293+
params.MasterTimeout = masterTimeout
294294
params.WaitForActiveShards = model.WaitForActiveShards.ValueString()
295295
}
296296

internal/elasticsearch/index/index/models_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
fuzz "github.com/google/gofuzz"
99

10+
"github.com/elastic/terraform-provider-elasticstack/internal/clients"
1011
"github.com/elastic/terraform-provider-elasticstack/internal/models"
1112
"github.com/elastic/terraform-provider-elasticstack/internal/utils/customtypes"
1213
"github.com/hashicorp/terraform-plugin-framework-jsontypes/jsontypes"
@@ -363,8 +364,9 @@ func Test_tfModel_toPutIndexParams(t *testing.T) {
363364

364365
flavor := "not_serverless"
365366
if isServerless {
366-
flavor = "serverless"
367+
flavor = clients.ServerlessFlavor
367368
expectedParams.WaitForActiveShards = ""
369+
expectedParams.MasterTimeout = 0
368370
}
369371

370372
params := model.toPutIndexParams(flavor)
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
package ingest
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"strings"
7+
8+
"github.com/elastic/terraform-provider-elasticstack/internal/models"
9+
"github.com/elastic/terraform-provider-elasticstack/internal/utils"
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
11+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
12+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
13+
)
14+
15+
func DataSourceProcessorReroute() *schema.Resource {
16+
processorSchema := map[string]*schema.Schema{
17+
"id": {
18+
Description: "Internal identifier of the resource.",
19+
Type: schema.TypeString,
20+
Computed: true,
21+
},
22+
"destination": {
23+
Description: "The destination data stream, index, or index alias to route the document to.",
24+
Type: schema.TypeString,
25+
Optional: true,
26+
},
27+
"dataset": {
28+
Description: "The destination dataset to route the document to.",
29+
Type: schema.TypeString,
30+
Optional: true,
31+
},
32+
"namespace": {
33+
Description: "The destination namespace to route the document to.",
34+
Type: schema.TypeString,
35+
Optional: true,
36+
},
37+
"description": {
38+
Description: "Description of the processor. ",
39+
Type: schema.TypeString,
40+
Optional: true,
41+
},
42+
"if": {
43+
Description: "Conditionally execute the processor",
44+
Type: schema.TypeString,
45+
Optional: true,
46+
},
47+
"ignore_failure": {
48+
Description: "Ignore failures for the processor. ",
49+
Type: schema.TypeBool,
50+
Optional: true,
51+
Default: false,
52+
},
53+
"on_failure": {
54+
Description: "Handle failures for the processor.",
55+
Type: schema.TypeList,
56+
Optional: true,
57+
MinItems: 1,
58+
Elem: &schema.Schema{
59+
Type: schema.TypeString,
60+
ValidateFunc: validation.StringIsJSON,
61+
DiffSuppressFunc: utils.DiffJsonSuppress,
62+
},
63+
},
64+
"tag": {
65+
Description: "Identifier for the processor.",
66+
Type: schema.TypeString,
67+
Optional: true,
68+
},
69+
"json": {
70+
Description: "JSON representation of this data source.",
71+
Type: schema.TypeString,
72+
Computed: true,
73+
},
74+
}
75+
76+
return &schema.Resource{
77+
Description: "Reroutes a document to a different data stream, index, or index alias. See: https://www.elastic.co/guide/en/elasticsearch/reference/current/reroute-processor.html",
78+
79+
ReadContext: dataSourceProcessorRerouteRead,
80+
81+
Schema: processorSchema,
82+
}
83+
}
84+
85+
func dataSourceProcessorRerouteRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
86+
var diags diag.Diagnostics
87+
88+
processor := &models.ProcessorReroute{}
89+
90+
processor.IgnoreFailure = d.Get("ignore_failure").(bool)
91+
92+
if v, ok := d.GetOk("destination"); ok {
93+
processor.Destination = v.(string)
94+
}
95+
if v, ok := d.GetOk("dataset"); ok {
96+
processor.Dataset = v.(string)
97+
}
98+
if v, ok := d.GetOk("namespace"); ok {
99+
processor.Namespace = v.(string)
100+
}
101+
102+
if v, ok := d.GetOk("description"); ok {
103+
processor.Description = v.(string)
104+
}
105+
if v, ok := d.GetOk("if"); ok {
106+
processor.If = v.(string)
107+
}
108+
if v, ok := d.GetOk("tag"); ok {
109+
processor.Tag = v.(string)
110+
}
111+
if v, ok := d.GetOk("on_failure"); ok {
112+
onFailure := make([]map[string]interface{}, len(v.([]interface{})))
113+
for i, f := range v.([]interface{}) {
114+
item := make(map[string]interface{})
115+
if err := json.NewDecoder(strings.NewReader(f.(string))).Decode(&item); err != nil {
116+
return diag.FromErr(err)
117+
}
118+
onFailure[i] = item
119+
}
120+
processor.OnFailure = onFailure
121+
}
122+
123+
processorJson, err := json.MarshalIndent(map[string]*models.ProcessorReroute{"reroute": processor}, "", " ")
124+
if err != nil {
125+
return diag.FromErr(err)
126+
}
127+
if err := d.Set("json", string(processorJson)); err != nil {
128+
return diag.FromErr(err)
129+
}
130+
131+
hash, err := utils.StringToHash(string(processorJson))
132+
if err != nil {
133+
return diag.FromErr(err)
134+
}
135+
136+
d.SetId(*hash)
137+
138+
return diags
139+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package ingest_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/elastic/terraform-provider-elasticstack/internal/acctest"
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
8+
)
9+
10+
func TestAccDataSourceIngestProcessorReroute(t *testing.T) {
11+
resource.Test(t, resource.TestCase{
12+
PreCheck: func() { acctest.PreCheck(t) },
13+
ProtoV6ProviderFactories: acctest.Providers,
14+
Steps: []resource.TestStep{
15+
{
16+
Config: testAccDataSourceIngestProcessorReroute,
17+
Check: resource.ComposeTestCheckFunc(
18+
CheckResourceJson("data.elasticstack_elasticsearch_ingest_processor_reroute.test", "json", expectedJsonReroute),
19+
),
20+
},
21+
},
22+
})
23+
}
24+
25+
const expectedJsonReroute = `{
26+
"reroute": {
27+
"ignore_failure": false,
28+
"destination": "logs-generic-default"
29+
}
30+
}`
31+
32+
const testAccDataSourceIngestProcessorReroute = `
33+
provider "elasticstack" {
34+
elasticsearch {}
35+
}
36+
37+
data "elasticstack_elasticsearch_ingest_processor_reroute" "test" {
38+
destination = "logs-generic-default"
39+
}
40+
`

0 commit comments

Comments
 (0)