Skip to content

Commit b96f0a4

Browse files
kroussouphillbaker
authored andcommitted
Fix id normalization for opensearch 1.1+
1 parent feb09ed commit b96f0a4

File tree

4 files changed

+428
-105
lines changed

4 files changed

+428
-105
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ jobs:
5858
ES_OPENDISTRO_IMAGE: "amazon/opendistro-for-elasticsearch:1.13.2"
5959
ES_KIBANA_IMAGE: "docker.elastic.co/kibana/kibana:7.17.4"
6060
- es-major-version: "7-opensearch"
61-
version: 1.0.0
61+
version: 1.1.0
6262
oss-image: "opensearchproject/opensearch"
6363
XPACK_IMAGE: "docker.elastic.co/elasticsearch/elasticsearch:7.10.1"
64-
ES_OPENDISTRO_IMAGE: "opensearchproject/opensearch:1.0.0"
64+
ES_OPENDISTRO_IMAGE: "opensearchproject/opensearch:1.1.0"
6565
ES_KIBANA_IMAGE: "" # opensearchproject/opensearch-dashboards:1.0.0"
6666
OPENSEARCH_PREFIX: "plugins.security"
6767
OSS_ENV_VAR: "plugins.security.disabled=true"

es/resource_elasticsearch_opendistro_ism_policy_test.go

Lines changed: 193 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import (
88
elastic7 "github.com/olivere/elastic/v7"
99
elastic6 "gopkg.in/olivere/elastic.v6"
1010

11+
"github.com/hashicorp/go-version"
1112
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1213
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
1314
)
1415

1516
func TestAccElasticsearchOpenDistroISMPolicy(t *testing.T) {
17+
opensearchVerionConstraints, _ := version.NewConstraint(">= 1.1, < 6")
1618
provider := Provider()
1719
diags := provider.Configure(context.Background(), &terraform.ResourceConfig{})
1820
if diags.HasError() {
@@ -32,7 +34,15 @@ func TestAccElasticsearchOpenDistroISMPolicy(t *testing.T) {
3234
config = testAccElasticsearchOpenDistroISMPolicyV6
3335
default:
3436
allowed = true
35-
config = testAccElasticsearchOpenDistroISMPolicyV7
37+
v, err := version.NewVersion(meta.(*ProviderConf).esVersion)
38+
if err != nil {
39+
t.Skipf("err: %s", err)
40+
}
41+
if opensearchVerionConstraints.Check(v) {
42+
config = testAccElasticsearchOpenDistroISMPolicyOpenSearch11
43+
} else {
44+
config = testAccElasticsearchOpenDistroISMPolicyV7
45+
}
3646
}
3747

3848
resource.Test(t, resource.TestCase{
@@ -128,53 +138,61 @@ var testAccElasticsearchOpenDistroISMPolicyV6 = `
128138
resource "elasticsearch_opendistro_ism_policy" "test_policy" {
129139
policy_id = "test_policy"
130140
body = <<EOF
131-
{
132-
"policy": {
133-
"description": "ingesting logs",
134-
"default_state": "ingest",
135-
"error_notification": {
136-
"destination": {
137-
"slack": {
138-
"url": "https://webhook.slack.example.com"
139-
}
140-
},
141-
"message_template": {
142-
"lang": "mustache",
143-
"source": "The index *{{ctx.index}}* failed to rollover."
141+
{
142+
"policy": {
143+
"description": "ingesting logs",
144+
"default_state": "ingest",
145+
"error_notification": {
146+
"destination": {
147+
"slack": {
148+
"url": "https://webhook.slack.example.com"
144149
}
145150
},
146-
"states": [
147-
{
148-
"name": "ingest",
149-
"actions": [{
150-
"rollover": {
151-
"min_doc_count": 5
152-
}
153-
}],
154-
"transitions": [{
155-
"state_name": "search"
156-
}]
157-
},
158-
{
159-
"name": "search",
160-
"actions": [],
161-
"transitions": [{
162-
"state_name": "delete",
163-
"conditions": {
164-
"min_index_age": "5m"
165-
}
166-
}]
167-
},
168-
{
169-
"name": "delete",
170-
"actions": [{
171-
"delete": {}
172-
}],
173-
"transitions": []
174-
}
175-
]
176-
}
177-
}
151+
"message_template": {
152+
"lang": "mustache",
153+
"source": "The index *{{ctx.index}}* failed to rollover."
154+
}
155+
},
156+
"states": [
157+
{
158+
"name": "ingest",
159+
"actions": [
160+
{
161+
"rollover": {
162+
"min_doc_count": 5
163+
}
164+
}
165+
],
166+
"transitions": [
167+
{
168+
"state_name": "search"
169+
}
170+
]
171+
},
172+
{
173+
"name": "search",
174+
"actions": [],
175+
"transitions": [
176+
{
177+
"state_name": "delete",
178+
"conditions": {
179+
"min_index_age": "5m"
180+
}
181+
}
182+
]
183+
},
184+
{
185+
"name": "delete",
186+
"actions": [
187+
{
188+
"delete": {}
189+
}
190+
],
191+
"transitions": []
192+
}
193+
]
194+
}
195+
}
178196
EOF
179197
}
180198
`
@@ -183,57 +201,138 @@ var testAccElasticsearchOpenDistroISMPolicyV7 = `
183201
resource "elasticsearch_opendistro_ism_policy" "test_policy" {
184202
policy_id = "test_policy"
185203
body = <<EOF
186-
{
187-
"policy": {
188-
"description": "ingesting logs",
189-
"default_state": "ingest",
190-
"ism_template": {
191-
"index_patterns": ["foo-*"],
192-
"priority": 0
193-
},
194-
"error_notification": {
195-
"destination": {
196-
"slack": {
197-
"url": "https://webhook.slack.example.com"
204+
{
205+
"policy": {
206+
"description": "ingesting logs",
207+
"default_state": "ingest",
208+
"ism_template": {
209+
"index_patterns": [
210+
"foo-*"
211+
],
212+
"priority": 0
213+
},
214+
"error_notification": {
215+
"destination": {
216+
"slack": {
217+
"url": "https://webhook.slack.example.com"
218+
}
219+
},
220+
"message_template": {
221+
"lang": "mustache",
222+
"source": "The index *{{ctx.index}}* failed to rollover."
223+
}
224+
},
225+
"states": [
226+
{
227+
"name": "ingest",
228+
"actions": [
229+
{
230+
"rollover": {
231+
"min_doc_count": 5
232+
}
233+
}
234+
],
235+
"transitions": [
236+
{
237+
"state_name": "search"
238+
}
239+
]
240+
},
241+
{
242+
"name": "search",
243+
"actions": [],
244+
"transitions": [
245+
{
246+
"state_name": "delete",
247+
"conditions": {
248+
"min_index_age": "5m"
249+
}
198250
}
199-
},
200-
"message_template": {
201-
"lang": "mustache",
202-
"source": "The index *{{ctx.index}}* failed to rollover."
251+
]
252+
},
253+
{
254+
"name": "delete",
255+
"actions": [
256+
{
257+
"delete": {}
258+
}
259+
],
260+
"transitions": []
261+
}
262+
]
263+
}
264+
}
265+
EOF
266+
}
267+
`
268+
269+
var testAccElasticsearchOpenDistroISMPolicyOpenSearch11 = `
270+
resource "elasticsearch_opendistro_ism_policy" "test_policy" {
271+
policy_id = "test_policy"
272+
body = <<EOF
273+
{
274+
"policy":{
275+
"description":"ingesting logs",
276+
"default_state":"ingest",
277+
"ism_template":[
278+
{
279+
"index_patterns":[
280+
"foo-*"
281+
],
282+
"priority":0
283+
}
284+
],
285+
"error_notification":{
286+
"destination":{
287+
"slack":{
288+
"url":"https://webhook.slack.example.com"
203289
}
204290
},
205-
"states": [
206-
{
207-
"name": "ingest",
208-
"actions": [{
209-
"rollover": {
210-
"min_doc_count": 5
211-
}
212-
}],
213-
"transitions": [{
214-
"state_name": "search"
215-
}]
216-
},
217-
{
218-
"name": "search",
219-
"actions": [],
220-
"transitions": [{
221-
"state_name": "delete",
222-
"conditions": {
223-
"min_index_age": "5m"
224-
}
225-
}]
226-
},
227-
{
228-
"name": "delete",
229-
"actions": [{
230-
"delete": {}
231-
}],
232-
"transitions": []
233-
}
234-
]
235-
}
236-
}
291+
"message_template":{
292+
"lang":"mustache",
293+
"source":"The index *{{ctx.index}}* failed to rollover."
294+
}
295+
},
296+
"states":[
297+
{
298+
"name":"ingest",
299+
"actions":[
300+
{
301+
"rollover":{
302+
"min_doc_count":5
303+
}
304+
}
305+
],
306+
"transitions":[
307+
{
308+
"state_name":"search"
309+
}
310+
]
311+
},
312+
{
313+
"name":"search",
314+
"actions":[],
315+
"transitions":[
316+
{
317+
"state_name":"delete",
318+
"conditions":{
319+
"min_index_age":"5m"
320+
}
321+
}
322+
]
323+
},
324+
{
325+
"name":"delete",
326+
"actions":[
327+
{
328+
"delete":{}
329+
}
330+
],
331+
"transitions":[]
332+
}
333+
]
334+
}
335+
}
237336
EOF
238337
}
239338
`

0 commit comments

Comments
 (0)