@@ -2,6 +2,7 @@ package main
2
2
3
3
import (
4
4
"context"
5
+ "errors"
5
6
"encoding/json"
6
7
"fmt"
7
8
"log"
@@ -46,8 +47,7 @@ func resourceElasticsearchKibanaObjectCreate(d *schema.ResourceData, meta interf
46
47
var err error
47
48
switch meta .(type ) {
48
49
case * elastic7.Client :
49
- client := meta .(* elastic7.Client )
50
- success , err = elastic7CreateIndexIfNotExists (client , index , mapping_index )
50
+ err = errors .New ("kibana objects not implemented post to Elastic v7" )
51
51
case * elastic6.Client :
52
52
client := meta .(* elastic6.Client )
53
53
success , err = elastic6CreateIndexIfNotExists (client , index , mapping_index )
@@ -80,26 +80,6 @@ func resourceElasticsearchKibanaObjectCreate(d *schema.ResourceData, meta interf
80
80
return nil
81
81
}
82
82
83
- func elastic7CreateIndexIfNotExists (client * elastic7.Client , index string , mapping_index string ) (int , error ) {
84
- log .Printf ("[INFO] elastic7CreateIndexIfNotExists" )
85
-
86
- // Use the IndexExists service to check if a specified index exists.
87
- exists , err := client .IndexExists (index ).Do (context .TODO ())
88
- if err != nil {
89
- return INDEX_CREATION_FAILED , err
90
- }
91
- if ! exists {
92
- createIndex , err := client .CreateIndex (mapping_index ).Body (`{"mappings":{}}` ).Do (context .TODO ())
93
- if createIndex .Acknowledged {
94
- return INDEX_CREATED , err
95
- } else {
96
- return INDEX_CREATION_FAILED , err
97
- }
98
- }
99
-
100
- return INDEX_EXISTS , nil
101
- }
102
-
103
83
func elastic6CreateIndexIfNotExists (client * elastic6.Client , index string , mapping_index string ) (int , error ) {
104
84
log .Printf ("[INFO] elastic6CreateIndexIfNotExists" )
105
85
@@ -165,14 +145,11 @@ func resourceElasticsearchKibanaObjectRead(d *schema.ResourceData, meta interfac
165
145
objectType := body [0 ]["_type" ].(string )
166
146
index := d .Get ("index" ).(string )
167
147
168
- var rawMessage json.RawMessage
169
148
var result * json.RawMessage
170
149
var err error
171
150
switch meta .(type ) {
172
151
case * elastic7.Client :
173
- client := meta .(* elastic7.Client )
174
- rawMessage , err = elastic7GetObject (client , objectType , index , id )
175
- result = & rawMessage
152
+ err = errors .New ("kibana objects not implemented post to Elastic v7" )
176
153
case * elastic6.Client :
177
154
client := meta .(* elastic6.Client )
178
155
result , err = elastic6GetObject (client , objectType , index , id )
@@ -182,7 +159,7 @@ func resourceElasticsearchKibanaObjectRead(d *schema.ResourceData, meta interfac
182
159
}
183
160
184
161
if err != nil {
185
- if elastic7 . IsNotFound ( err ) || elastic6 .IsNotFound (err ) || elastic5 .IsNotFound (err ) {
162
+ if elastic6 .IsNotFound (err ) || elastic5 .IsNotFound (err ) {
186
163
log .Printf ("[WARN] Kibana Object (%s) not found, removing from state" , id )
187
164
d .SetId ("" )
188
165
return nil
@@ -197,23 +174,6 @@ func resourceElasticsearchKibanaObjectRead(d *schema.ResourceData, meta interfac
197
174
return nil
198
175
}
199
176
200
- func elastic7GetObject (client * elastic7.Client , objectType string , index string , id string ) (json.RawMessage , error ) {
201
- result , err := client .Get ().
202
- Index (index ).
203
- Type (objectType ).
204
- Id (id ).
205
- Do (context .TODO ())
206
-
207
- if err != nil {
208
- return nil , err
209
- }
210
- if ! result .Found {
211
- return nil , fmt .Errorf ("Object not found." )
212
- }
213
-
214
- return result .Source , nil
215
- }
216
-
217
177
func elastic6GetObject (client * elastic6.Client , objectType string , index string , id string ) (* json.RawMessage , error ) {
218
178
result , err := client .Get ().
219
179
Index (index ).
@@ -268,8 +228,7 @@ func resourceElasticsearchKibanaObjectDelete(d *schema.ResourceData, meta interf
268
228
var err error
269
229
switch meta .(type ) {
270
230
case * elastic7.Client :
271
- client := meta .(* elastic7.Client )
272
- err = elastic7DeleteIndex (client , objectType , index , id )
231
+ err = errors .New ("kibana objects not implemented post to Elastic v7" )
273
232
case * elastic6.Client :
274
233
client := meta .(* elastic6.Client )
275
234
err = elastic6DeleteIndex (client , objectType , index , id )
@@ -285,17 +244,6 @@ func resourceElasticsearchKibanaObjectDelete(d *schema.ResourceData, meta interf
285
244
return nil
286
245
}
287
246
288
- func elastic7DeleteIndex (client * elastic7.Client , objectType string , index string , id string ) error {
289
- _ , err := client .Delete ().
290
- Index (index ).
291
- Type (objectType ).
292
- Id (id ).
293
- Do (context .TODO ())
294
-
295
- // we'll get an error if it's not found: https://github.com/olivere/elastic/blob/v6.1.26/delete.go#L207-L210
296
- return err
297
- }
298
-
299
247
func elastic6DeleteIndex (client * elastic6.Client , objectType string , index string , id string ) error {
300
248
_ , err := client .Delete ().
301
249
Index (index ).
@@ -334,8 +282,7 @@ func resourceElasticsearchPutKibanaObject(d *schema.ResourceData, meta interface
334
282
var err error
335
283
switch meta .(type ) {
336
284
case * elastic7.Client :
337
- client := meta .(* elastic7.Client )
338
- err = elastic7PutIndex (client , objectType , index , id , data )
285
+ err = errors .New ("kibana objects not implemented post to Elastic v7" )
339
286
case * elastic6.Client :
340
287
client := meta .(* elastic6.Client )
341
288
err = elastic6PutIndex (client , objectType , index , id , data )
@@ -351,17 +298,6 @@ func resourceElasticsearchPutKibanaObject(d *schema.ResourceData, meta interface
351
298
return id , nil
352
299
}
353
300
354
- func elastic7PutIndex (client * elastic7.Client , objectType string , index string , id string , data interface {}) error {
355
- _ , err := client .Index ().
356
- Index (index ).
357
- Type (objectType ).
358
- Id (id ).
359
- BodyJson (& data ).
360
- Do (context .TODO ())
361
-
362
- return err
363
- }
364
-
365
301
func elastic6PutIndex (client * elastic6.Client , objectType string , index string , id string , data interface {}) error {
366
302
_ , err := client .Index ().
367
303
Index (index ).
0 commit comments