@@ -16,7 +16,7 @@ import (
16
16
var (
17
17
databaseSecretBackendConnectionBackendFromPathRegex = regexp .MustCompile ("^(.+)/config/.+$" )
18
18
databaseSecretBackendConnectionNameFromPathRegex = regexp .MustCompile ("^.+/config/(.+$)" )
19
- dbBackendTypes = []string {"cassandra" , "hana" , "mongodb" , "mssql" , "mysql" , "mysql_rds" , "mysql_aurora" , "mysql_legacy" , "postgresql" , "oracle" }
19
+ dbBackendTypes = []string {"cassandra" , "hana" , "mongodb" , "mssql" , "mysql" , "mysql_rds" , "mysql_aurora" , "mysql_legacy" , "postgresql" , "oracle" , "elasticsearch" }
20
20
)
21
21
22
22
func databaseSecretBackendConnectionResource () * schema.Resource {
@@ -66,6 +66,34 @@ func databaseSecretBackendConnectionResource() *schema.Resource {
66
66
Sensitive : true ,
67
67
},
68
68
69
+ "elasticsearch" : {
70
+ Type : schema .TypeList ,
71
+ Optional : true ,
72
+ Description : "Connection parameters for the elasticsearch-database-plugin." ,
73
+ Elem : & schema.Resource {
74
+ Schema : map [string ]* schema.Schema {
75
+ "url" : {
76
+ Type : schema .TypeString ,
77
+ Required : true ,
78
+ Description : "The URL for Elasticsearch's API" ,
79
+ },
80
+ "username" : {
81
+ Type : schema .TypeString ,
82
+ Required : true ,
83
+ Description : "The username to be used in the connection URL" ,
84
+ },
85
+ "password" : {
86
+ Type : schema .TypeString ,
87
+ Required : true ,
88
+ Description : "The password to be used in the connection URL" ,
89
+ Sensitive : true ,
90
+ },
91
+ },
92
+ },
93
+ MaxItems : 1 ,
94
+ ConflictsWith : util .CalculateConflictsWith ("elasticsearch" , dbBackendTypes ),
95
+ },
96
+
69
97
"cassandra" : {
70
98
Type : schema .TypeList ,
71
99
Optional : true ,
@@ -281,6 +309,8 @@ func getDatabasePluginName(d *schema.ResourceData) (string, error) {
281
309
return "oracle-database-plugin" , nil
282
310
case len (d .Get ("postgresql" ).([]interface {})) > 0 :
283
311
return "postgresql-database-plugin" , nil
312
+ case len (d .Get ("elasticsearch" ).([]interface {})) > 0 :
313
+ return "elasticsearch-database-plugin" , nil
284
314
default :
285
315
return "" , fmt .Errorf ("at least one database plugin must be configured" )
286
316
}
@@ -353,6 +383,8 @@ func getDatabaseAPIData(d *schema.ResourceData) (map[string]interface{}, error)
353
383
setDatabaseConnectionData (d , "oracle.0." , data )
354
384
case "postgresql-database-plugin" :
355
385
setDatabaseConnectionData (d , "postgresql.0." , data )
386
+ case "elasticsearch-database-plugin" :
387
+ setElasticsearchDatabaseConnectionData (d , "elasticsearch.0." , data )
356
388
}
357
389
358
390
return data , nil
@@ -399,6 +431,34 @@ func getConnectionDetailsFromResponse(d *schema.ResourceData, prefix string, res
399
431
return []map [string ]interface {}{result }
400
432
}
401
433
434
+ func getElasticsearchConnectionDetailsFromResponse (d * schema.ResourceData , prefix string , resp * api.Secret ) []map [string ]interface {} {
435
+ details := resp .Data ["connection_details" ]
436
+ data , ok := details .(map [string ]interface {})
437
+ if ! ok {
438
+ return nil
439
+ }
440
+ result := map [string ]interface {}{}
441
+ if v , ok := d .GetOk (prefix + "url" ); ok {
442
+ result ["url" ] = v .(string )
443
+ } else {
444
+ if v , ok := data ["url" ]; ok {
445
+ result ["url" ] = v .(string )
446
+ }
447
+ }
448
+
449
+ if v , ok := data ["username" ]; ok {
450
+ result ["username" ] = v .(string )
451
+ }
452
+ if v , ok := data ["password" ]; ok {
453
+ result ["password" ] = v .(string )
454
+ } else if v , ok := d .GetOk (prefix + "password" ); ok {
455
+ // keep the password we have in state/config if the API doesn't return one
456
+ result ["password" ] = v .(string )
457
+ }
458
+
459
+ return []map [string ]interface {}{result }
460
+ }
461
+
402
462
func setDatabaseConnectionData (d * schema.ResourceData , prefix string , data map [string ]interface {}) {
403
463
if v , ok := d .GetOk (prefix + "connection_url" ); ok {
404
464
data ["connection_url" ] = v .(string )
@@ -414,6 +474,20 @@ func setDatabaseConnectionData(d *schema.ResourceData, prefix string, data map[s
414
474
}
415
475
}
416
476
477
+ func setElasticsearchDatabaseConnectionData (d * schema.ResourceData , prefix string , data map [string ]interface {}) {
478
+ if v , ok := d .GetOk (prefix + "url" ); ok {
479
+ data ["url" ] = v .(string )
480
+ }
481
+
482
+ if v , ok := d .GetOk (prefix + "username" ); ok {
483
+ data ["username" ] = v .(string )
484
+ }
485
+
486
+ if v , ok := d .GetOk (prefix + "password" ); ok {
487
+ data ["password" ] = v .(string )
488
+ }
489
+ }
490
+
417
491
func databaseSecretBackendConnectionCreate (d * schema.ResourceData , meta interface {}) error {
418
492
client := meta .(* api.Client )
419
493
@@ -564,6 +638,8 @@ func databaseSecretBackendConnectionRead(d *schema.ResourceData, meta interface{
564
638
d .Set ("oracle" , getConnectionDetailsFromResponse (d , "oracle.0." , resp ))
565
639
case "postgresql-database-plugin" :
566
640
d .Set ("postgresql" , getConnectionDetailsFromResponse (d , "postgresql.0." , resp ))
641
+ case "elasticsearch-database-plugin" :
642
+ d .Set ("elasticsearch" , getElasticsearchConnectionDetailsFromResponse (d , "elasticsearch.0." , resp ))
567
643
}
568
644
569
645
if err != nil {
0 commit comments