@@ -10,18 +10,51 @@ import (
1010
1111 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1212 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
13- "github.com/hashicorp/terraform-provider-vault/util"
1413 "github.com/hashicorp/vault/api"
14+
15+ "github.com/hashicorp/terraform-provider-vault/util"
1516)
1617
1718type connectionStringConfig struct {
1819 excludeUsernameTemplate bool
1920}
2021
22+ const (
23+ dbBackendCassandra = "cassandra"
24+ dbBackendElasticSearch = "elasticsearch"
25+ dbBackendHana = "hana"
26+ dbBackendInfluxDB = "influxdb"
27+ dbBackendMSSQL = "mssql"
28+ dbBackendMongoDB = "mongodb"
29+ dbBackendMongoDBAtlas = "mongodbatlas"
30+ dbBackendMySQL = "mysql"
31+ dbBackendMySQLAurora = "mysql_aurora"
32+ dbBackendMySQLLegacy = "mysql_legacy"
33+ dbBackendMySQLRDS = "mysql_rds"
34+ dbBackendPostgres = "postgresql"
35+ dbBackendOracle = "oracle"
36+ dbBackendSnowflake = "snowflake"
37+ )
38+
2139var (
2240 databaseSecretBackendConnectionBackendFromPathRegex = regexp .MustCompile ("^(.+)/config/.+$" )
2341 databaseSecretBackendConnectionNameFromPathRegex = regexp .MustCompile ("^.+/config/(.+$)" )
24- dbBackendTypes = []string {"cassandra" , "influxdb" , "hana" , "mongodb" , "mssql" , "mysql" , "mysql_rds" , "mysql_aurora" , "mysql_legacy" , "postgresql" , "oracle" , "elasticsearch" , "snowflake" }
42+ dbBackendTypes = []string {
43+ dbBackendCassandra ,
44+ dbBackendElasticSearch ,
45+ dbBackendHana ,
46+ dbBackendInfluxDB ,
47+ dbBackendMSSQL ,
48+ dbBackendMongoDB ,
49+ dbBackendMongoDBAtlas ,
50+ dbBackendMySQL ,
51+ dbBackendMySQLAurora ,
52+ dbBackendMySQLLegacy ,
53+ dbBackendMySQLRDS ,
54+ dbBackendPostgres ,
55+ dbBackendOracle ,
56+ dbBackendSnowflake ,
57+ }
2558)
2659
2760func databaseSecretBackendConnectionResource () * schema.Resource {
@@ -96,7 +129,7 @@ func databaseSecretBackendConnectionResource() *schema.Resource {
96129 },
97130 },
98131 MaxItems : 1 ,
99- ConflictsWith : util .CalculateConflictsWith ("elasticsearch" , dbBackendTypes ),
132+ ConflictsWith : util .CalculateConflictsWith (dbBackendElasticSearch , dbBackendTypes ),
100133 },
101134
102135 "cassandra" : {
@@ -171,7 +204,7 @@ func databaseSecretBackendConnectionResource() *schema.Resource {
171204 },
172205 },
173206 MaxItems : 1 ,
174- ConflictsWith : util .CalculateConflictsWith ("cassandra" , dbBackendTypes ),
207+ ConflictsWith : util .CalculateConflictsWith (dbBackendCassandra , dbBackendTypes ),
175208 },
176209
177210 "influxdb" : {
@@ -242,7 +275,7 @@ func databaseSecretBackendConnectionResource() *schema.Resource {
242275 },
243276 },
244277 MaxItems : 1 ,
245- ConflictsWith : util .CalculateConflictsWith ("influxdb" , dbBackendTypes ),
278+ ConflictsWith : util .CalculateConflictsWith (dbBackendInfluxDB , dbBackendTypes ),
246279 },
247280
248281 "mongodb" : {
@@ -251,7 +284,7 @@ func databaseSecretBackendConnectionResource() *schema.Resource {
251284 Description : "Connection parameters for the mongodb-database-plugin plugin." ,
252285 Elem : connectionStringResource (& connectionStringConfig {}),
253286 MaxItems : 1 ,
254- ConflictsWith : util .CalculateConflictsWith ("mongodb" , dbBackendTypes ),
287+ ConflictsWith : util .CalculateConflictsWith (dbBackendMongoDB , dbBackendTypes ),
255288 },
256289
257290 "mongodbatlas" : {
@@ -279,7 +312,7 @@ func databaseSecretBackendConnectionResource() *schema.Resource {
279312 },
280313 },
281314 MaxItems : 1 ,
282- ConflictsWith : util .CalculateConflictsWith ("mongodbatlas" , dbBackendTypes ),
315+ ConflictsWith : util .CalculateConflictsWith (dbBackendMongoDBAtlas , dbBackendTypes ),
283316 },
284317
285318 "hana" : {
@@ -290,16 +323,16 @@ func databaseSecretBackendConnectionResource() *schema.Resource {
290323 excludeUsernameTemplate : true ,
291324 }),
292325 MaxItems : 1 ,
293- ConflictsWith : util .CalculateConflictsWith ("hana" , dbBackendTypes ),
326+ ConflictsWith : util .CalculateConflictsWith (dbBackendHana , dbBackendTypes ),
294327 },
295328
296329 "mssql" : {
297330 Type : schema .TypeList ,
298331 Optional : true ,
299332 Description : "Connection parameters for the mssql-database-plugin plugin." ,
300- Elem : connectionStringResource ( & connectionStringConfig {} ),
333+ Elem : mssqlConnectionStringResource ( ),
301334 MaxItems : 1 ,
302- ConflictsWith : util .CalculateConflictsWith ("mssql" , dbBackendTypes ),
335+ ConflictsWith : util .CalculateConflictsWith (dbBackendMSSQL , dbBackendTypes ),
303336 },
304337
305338 "mysql" : {
@@ -308,31 +341,31 @@ func databaseSecretBackendConnectionResource() *schema.Resource {
308341 Description : "Connection parameters for the mysql-database-plugin plugin." ,
309342 Elem : mysqlConnectionStringResource (),
310343 MaxItems : 1 ,
311- ConflictsWith : util .CalculateConflictsWith ("mysql" , dbBackendTypes ),
344+ ConflictsWith : util .CalculateConflictsWith (dbBackendMySQL , dbBackendTypes ),
312345 },
313346 "mysql_rds" : {
314347 Type : schema .TypeList ,
315348 Optional : true ,
316349 Description : "Connection parameters for the mysql-rds-database-plugin plugin." ,
317350 Elem : connectionStringResource (& connectionStringConfig {}),
318351 MaxItems : 1 ,
319- ConflictsWith : util .CalculateConflictsWith ("mysql_rds" , dbBackendTypes ),
352+ ConflictsWith : util .CalculateConflictsWith (dbBackendMySQLRDS , dbBackendTypes ),
320353 },
321354 "mysql_aurora" : {
322355 Type : schema .TypeList ,
323356 Optional : true ,
324357 Description : "Connection parameters for the mysql-aurora-database-plugin plugin." ,
325358 Elem : connectionStringResource (& connectionStringConfig {}),
326359 MaxItems : 1 ,
327- ConflictsWith : util .CalculateConflictsWith ("mysql_aurora" , dbBackendTypes ),
360+ ConflictsWith : util .CalculateConflictsWith (dbBackendMySQLAurora , dbBackendTypes ),
328361 },
329362 "mysql_legacy" : {
330363 Type : schema .TypeList ,
331364 Optional : true ,
332365 Description : "Connection parameters for the mysql-legacy-database-plugin plugin." ,
333366 Elem : connectionStringResource (& connectionStringConfig {}),
334367 MaxItems : 1 ,
335- ConflictsWith : util .CalculateConflictsWith ("mysql_legacy" , dbBackendTypes ),
368+ ConflictsWith : util .CalculateConflictsWith (dbBackendMySQLLegacy , dbBackendTypes ),
336369 },
337370
338371 "postgresql" : {
@@ -341,7 +374,7 @@ func databaseSecretBackendConnectionResource() *schema.Resource {
341374 Description : "Connection parameters for the postgresql-database-plugin plugin." ,
342375 Elem : connectionStringResource (& connectionStringConfig {}),
343376 MaxItems : 1 ,
344- ConflictsWith : util .CalculateConflictsWith ("postgresql" , dbBackendTypes ),
377+ ConflictsWith : util .CalculateConflictsWith (dbBackendPostgres , dbBackendTypes ),
345378 },
346379
347380 "oracle" : {
@@ -350,7 +383,7 @@ func databaseSecretBackendConnectionResource() *schema.Resource {
350383 Description : "Connection parameters for the oracle-database-plugin plugin." ,
351384 Elem : connectionStringResource (& connectionStringConfig {}),
352385 MaxItems : 1 ,
353- ConflictsWith : util .CalculateConflictsWith ("oracle" , dbBackendTypes ),
386+ ConflictsWith : util .CalculateConflictsWith (dbBackendOracle , dbBackendTypes ),
354387 },
355388
356389 "snowflake" : {
@@ -359,7 +392,7 @@ func databaseSecretBackendConnectionResource() *schema.Resource {
359392 Description : "Connection parameters for the snowflake-database-plugin plugin." ,
360393 Elem : snowflakeConnectionStringResource (),
361394 MaxItems : 1 ,
362- ConflictsWith : util .CalculateConflictsWith ("snowflake" , dbBackendTypes ),
395+ ConflictsWith : util .CalculateConflictsWith (dbBackendSnowflake , dbBackendTypes ),
363396 },
364397
365398 "backend" : {
@@ -430,6 +463,16 @@ func mysqlConnectionStringResource() *schema.Resource {
430463 return r
431464}
432465
466+ func mssqlConnectionStringResource () * schema.Resource {
467+ r := connectionStringResource (& connectionStringConfig {})
468+ r .Schema ["contain_db" ] = & schema.Schema {
469+ Type : schema .TypeBool ,
470+ Optional : true ,
471+ Description : "Set to true when the target is a Contained Database, e.g. AzureSQL." ,
472+ }
473+ return r
474+ }
475+
433476func snowflakeConnectionStringResource () * schema.Resource {
434477 r := connectionStringResource (& connectionStringConfig {})
435478 r .Schema ["username" ] = & schema.Schema {
@@ -448,33 +491,33 @@ func snowflakeConnectionStringResource() *schema.Resource {
448491
449492func getDatabasePluginName (d * schema.ResourceData ) (string , error ) {
450493 switch {
451- case len (d .Get ("cassandra" ).([]interface {})) > 0 :
494+ case len (d .Get (dbBackendCassandra ).([]interface {})) > 0 :
452495 return "cassandra-database-plugin" , nil
453- case len (d .Get ("influxdb" ).([]interface {})) > 0 :
496+ case len (d .Get (dbBackendInfluxDB ).([]interface {})) > 0 :
454497 return "influxdb-database-plugin" , nil
455- case len (d .Get ("hana" ).([]interface {})) > 0 :
498+ case len (d .Get (dbBackendHana ).([]interface {})) > 0 :
456499 return "hana-database-plugin" , nil
457- case len (d .Get ("mongodbatlas" ).([]interface {})) > 0 :
500+ case len (d .Get (dbBackendMongoDBAtlas ).([]interface {})) > 0 :
458501 return "mongodbatlas-database-plugin" , nil
459- case len (d .Get ("mongodb" ).([]interface {})) > 0 :
502+ case len (d .Get (dbBackendMongoDB ).([]interface {})) > 0 :
460503 return "mongodb-database-plugin" , nil
461- case len (d .Get ("mssql" ).([]interface {})) > 0 :
504+ case len (d .Get (dbBackendMSSQL ).([]interface {})) > 0 :
462505 return "mssql-database-plugin" , nil
463- case len (d .Get ("mysql" ).([]interface {})) > 0 :
506+ case len (d .Get (dbBackendMySQL ).([]interface {})) > 0 :
464507 return "mysql-database-plugin" , nil
465- case len (d .Get ("mysql_rds" ).([]interface {})) > 0 :
508+ case len (d .Get (dbBackendMySQLRDS ).([]interface {})) > 0 :
466509 return "mysql-rds-database-plugin" , nil
467- case len (d .Get ("mysql_aurora" ).([]interface {})) > 0 :
510+ case len (d .Get (dbBackendMySQLAurora ).([]interface {})) > 0 :
468511 return "mysql-aurora-database-plugin" , nil
469- case len (d .Get ("mysql_legacy" ).([]interface {})) > 0 :
512+ case len (d .Get (dbBackendMySQLLegacy ).([]interface {})) > 0 :
470513 return "mysql-legacy-database-plugin" , nil
471- case len (d .Get ("oracle" ).([]interface {})) > 0 :
514+ case len (d .Get (dbBackendOracle ).([]interface {})) > 0 :
472515 return "oracle-database-plugin" , nil
473- case len (d .Get ("postgresql" ).([]interface {})) > 0 :
516+ case len (d .Get (dbBackendPostgres ).([]interface {})) > 0 :
474517 return "postgresql-database-plugin" , nil
475- case len (d .Get ("elasticsearch" ).([]interface {})) > 0 :
518+ case len (d .Get (dbBackendElasticSearch ).([]interface {})) > 0 :
476519 return "elasticsearch-database-plugin" , nil
477- case len (d .Get ("snowflake" ).([]interface {})) > 0 :
520+ case len (d .Get (dbBackendSnowflake ).([]interface {})) > 0 :
478521 return "snowflake-database-plugin" , nil
479522 default :
480523 return "" , fmt .Errorf ("at least one database plugin must be configured" )
0 commit comments