Skip to content

Commit 0c2b254

Browse files
authored
Merge pull request #623 from ovh/no-backups-engine
fix kafka + add kafka_schema_registry attribute
2 parents 5a2e0a2 + 16814f7 commit 0c2b254

5 files changed

+91
-79
lines changed

Diff for: ovh/data_cloud_project_database.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ func dataSourceCloudProjectDatabase() *schema.Resource {
135135
Description: "Defines whether the REST API is enabled on a Kafka cluster",
136136
Computed: true,
137137
},
138+
"kafka_schema_registry": {
139+
Type: schema.TypeBool,
140+
Description: "Defines whether the schema registry is enabled on a Kafka cluster",
141+
Computed: true,
142+
},
138143
"maintenance_time": {
139144
Type: schema.TypeString,
140145
Description: "Time on which maintenances can start every day",
@@ -232,16 +237,16 @@ func dataSourceCloudProjectDatabaseRead(ctx context.Context, d *schema.ResourceD
232237
nodesEndpoint := fmt.Sprintf("%s/node", serviceEndpoint)
233238
nodeList := &[]string{}
234239
if err := config.OVHClient.GetWithContext(ctx, nodesEndpoint, nodeList); err != nil {
235-
return diag.Errorf("unable to get database %s nodes: %v", res.Id, err)
240+
return diag.Errorf("unable to get database %s nodes: %v", res.ID, err)
236241
}
237242

238243
if len(*nodeList) == 0 {
239-
return diag.Errorf("no node found for database %s", res.Id)
244+
return diag.Errorf("no node found for database %s", res.ID)
240245
}
241246
nodeEndpoint := fmt.Sprintf("%s/%s", nodesEndpoint, url.PathEscape((*nodeList)[0]))
242247
node := &CloudProjectDatabaseNodes{}
243248
if err := config.OVHClient.GetWithContext(ctx, nodeEndpoint, node); err != nil {
244-
return diag.Errorf("unable to get database %s node %s: %v", res.Id, (*nodeList)[0], err)
249+
return diag.Errorf("unable to get database %s node %s: %v", res.ID, (*nodeList)[0], err)
245250
}
246251

247252
res.Region = node.Region
@@ -250,12 +255,12 @@ func dataSourceCloudProjectDatabaseRead(ctx context.Context, d *schema.ResourceD
250255
advancedConfigEndpoint := fmt.Sprintf("%s/advancedConfiguration", serviceEndpoint)
251256
advancedConfigMap := &map[string]string{}
252257
if err := config.OVHClient.GetWithContext(ctx, advancedConfigEndpoint, advancedConfigMap); err != nil {
253-
return diag.Errorf("unable to get database %s advanced configuration: %v", res.Id, err)
258+
return diag.Errorf("unable to get database %s advanced configuration: %v", res.ID, err)
254259
}
255260
res.AdvancedConfiguration = *advancedConfigMap
256261
}
257262

258-
for k, v := range res.ToMap() {
263+
for k, v := range res.toMap() {
259264
if k != "id" {
260265
d.Set(k, v)
261266
} else {

Diff for: ovh/resource_cloud_project_database.go

+27-18
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ func resourceCloudProjectDatabase() *schema.Resource {
8585
return d.Get("engine").(string) != "kafka" || new == old
8686
},
8787
},
88+
"kafka_schema_registry": {
89+
Type: schema.TypeBool,
90+
Description: "Defines whether the schema registry is enabled on a Kafka cluster",
91+
Optional: true,
92+
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
93+
return d.Get("engine").(string) != "kafka" || new == old
94+
},
95+
},
8896
"nodes": {
8997
Type: schema.TypeList,
9098
Description: "List of nodes composing the service",
@@ -245,15 +253,15 @@ func resourceCloudProjectDatabase() *schema.Resource {
245253
}
246254

247255
func resourceCloudProjectDatabaseImportState(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
248-
givenId := d.Id()
256+
givenID := d.Id()
249257
n := 3
250-
splitId := strings.SplitN(givenId, "/", n)
251-
if len(splitId) != n {
258+
splitID := strings.SplitN(givenID, "/", n)
259+
if len(splitID) != n {
252260
return nil, fmt.Errorf("import Id is not service_name/engine/databaseId formatted")
253261
}
254-
serviceName := splitId[0]
255-
engine := splitId[1]
256-
id := splitId[2]
262+
serviceName := splitID[0]
263+
engine := splitID[1]
264+
id := splitID[2]
257265
d.SetId(id)
258266
d.Set("engine", engine)
259267
d.Set("service_name", serviceName)
@@ -272,7 +280,7 @@ func resourceCloudProjectDatabaseCreate(ctx context.Context, d *schema.ResourceD
272280
url.PathEscape(serviceName),
273281
url.PathEscape(engine),
274282
)
275-
params, err := (&CloudProjectDatabaseCreateOpts{}).FromResource(d)
283+
params, err := (&CloudProjectDatabaseCreateOpts{}).fromResource(d)
276284
if err != nil {
277285
return diag.Errorf("service creation failed : %q", err)
278286
}
@@ -284,17 +292,18 @@ func resourceCloudProjectDatabaseCreate(ctx context.Context, d *schema.ResourceD
284292
return diag.Errorf("calling Post %s with params %+v:\n\t %q", endpoint, params, err)
285293
}
286294

287-
log.Printf("[DEBUG] Waiting for database %s to be READY", res.Id)
288-
err = waitForCloudProjectDatabaseReady(ctx, config.OVHClient, serviceName, engine, res.Id, d.Timeout(schema.TimeoutCreate))
295+
log.Printf("[DEBUG] Waiting for database %s to be READY", res.ID)
296+
err = waitForCloudProjectDatabaseReady(ctx, config.OVHClient, serviceName, engine, res.ID, d.Timeout(schema.TimeoutCreate))
289297
if err != nil {
290-
return diag.Errorf("timeout while waiting database %s to be READY: %s", res.Id, err.Error())
298+
return diag.Errorf("timeout while waiting database %s to be READY: %s", res.ID, err.Error())
291299
}
292-
log.Printf("[DEBUG] database %s is READY", res.Id)
300+
log.Printf("[DEBUG] database %s is READY", res.ID)
293301

294-
d.SetId(res.Id)
302+
d.SetId(res.ID)
295303

296304
if (engine != "mongodb" && len(d.Get("advanced_configuration").(map[string]interface{})) > 0) ||
297305
(engine == "kafka" && d.Get("kafka_rest_api").(bool)) ||
306+
(engine == "kafka" && d.Get("kafka_schema_registry").(bool)) ||
298307
(engine == "opensearch" && d.Get("opensearch_acls_enabled").(bool)) {
299308
return resourceCloudProjectDatabaseUpdate(ctx, d, meta)
300309
}
@@ -322,16 +331,16 @@ func resourceCloudProjectDatabaseRead(ctx context.Context, d *schema.ResourceDat
322331
nodesEndpoint := fmt.Sprintf("%s/node", serviceEndpoint)
323332
nodeList := &[]string{}
324333
if err := config.OVHClient.GetWithContext(ctx, nodesEndpoint, nodeList); err != nil {
325-
return diag.Errorf("unable to get database %s nodes: %v", res.Id, err)
334+
return diag.Errorf("unable to get database %s nodes: %v", res.ID, err)
326335
}
327336

328337
if len(*nodeList) == 0 {
329-
return diag.Errorf("no node found for database %s", res.Id)
338+
return diag.Errorf("no node found for database %s", res.ID)
330339
}
331340
nodeEndpoint := fmt.Sprintf("%s/%s", nodesEndpoint, url.PathEscape((*nodeList)[0]))
332341
node := &CloudProjectDatabaseNodes{}
333342
if err := config.OVHClient.GetWithContext(ctx, nodeEndpoint, node); err != nil {
334-
return diag.Errorf("unable to get database %s node %s: %v", res.Id, (*nodeList)[0], err)
343+
return diag.Errorf("unable to get database %s node %s: %v", res.ID, (*nodeList)[0], err)
335344
}
336345

337346
res.Region = node.Region
@@ -340,12 +349,12 @@ func resourceCloudProjectDatabaseRead(ctx context.Context, d *schema.ResourceDat
340349
advancedConfigEndpoint := fmt.Sprintf("%s/advancedConfiguration", serviceEndpoint)
341350
advancedConfigMap := &map[string]string{}
342351
if err := config.OVHClient.GetWithContext(ctx, advancedConfigEndpoint, advancedConfigMap); err != nil {
343-
return diag.Errorf("unable to get database %s advanced configuration: %v", res.Id, err)
352+
return diag.Errorf("unable to get database %s advanced configuration: %v", res.ID, err)
344353
}
345354
res.AdvancedConfiguration = *advancedConfigMap
346355
}
347356

348-
for k, v := range res.ToMap() {
357+
for k, v := range res.toMap() {
349358
if k != "id" {
350359
d.Set(k, v)
351360
} else {
@@ -366,7 +375,7 @@ func resourceCloudProjectDatabaseUpdate(ctx context.Context, d *schema.ResourceD
366375
url.PathEscape(engine),
367376
url.PathEscape(d.Id()),
368377
)
369-
params, err := (&CloudProjectDatabaseUpdateOpts{}).FromResource(d)
378+
params, err := (&CloudProjectDatabaseUpdateOpts{}).fromResource(d)
370379
if err != nil {
371380
return diag.Errorf("service update failed : %q", err)
372381
}

Diff for: ovh/types_cloud_project_database.go

+50-43
Original file line numberDiff line numberDiff line change
@@ -67,69 +67,67 @@ type CloudProjectDatabaseResponse struct {
6767
Description string `json:"description"`
6868
Endpoints []CloudProjectDatabaseEndpoint `json:"endpoints"`
6969
Flavor string `json:"flavor"`
70-
Id string `json:"id"`
70+
ID string `json:"id"`
7171
IPRestrictions []CloudProjectDatabaseIPRestrictionResponse `json:"ipRestrictions"`
7272
MaintenanceTime string `json:"maintenanceTime"`
73-
NetworkId string `json:"networkId"`
73+
NetworkID string `json:"networkId"`
7474
NetworkType string `json:"networkType"`
7575
Plan string `json:"plan"`
7676
NodeNumber int `json:"nodeNumber"`
7777
Region string `json:"region"`
78-
RestApi bool `json:"restApi"`
78+
RestAPI bool `json:"restApi"`
79+
SchemaRegistry bool `json:"schemaRegistry"`
7980
Status string `json:"status"`
80-
SubnetId string `json:"subnetId"`
81+
SubnetID string `json:"subnetId"`
8182
Version string `json:"version"`
8283
Disk CloudProjectDatabaseDisk `json:"disk"`
8384
AdvancedConfiguration map[string]string `json:"advancedConfiguration"`
8485
}
8586

86-
func (s *CloudProjectDatabaseResponse) String() string {
87-
return fmt.Sprintf("%s(%s): %s", s.Description, s.Id, s.Status)
88-
}
89-
90-
func (v CloudProjectDatabaseResponse) ToMap() map[string]interface{} {
87+
func (r CloudProjectDatabaseResponse) toMap() map[string]interface{} {
9188
obj := make(map[string]interface{})
92-
obj["backup_regions"] = v.Backups.Regions
93-
obj["backup_time"] = v.Backups.Time
94-
obj["created_at"] = v.CreatedAt
95-
obj["description"] = v.Description
96-
obj["id"] = v.Id
89+
obj["backup_regions"] = r.Backups.Regions
90+
obj["backup_time"] = r.Backups.Time
91+
obj["created_at"] = r.CreatedAt
92+
obj["description"] = r.Description
93+
obj["id"] = r.ID
9794

9895
var ipRests []map[string]interface{}
99-
for _, ir := range v.IPRestrictions {
96+
for _, ir := range r.IPRestrictions {
10097
ipRests = append(ipRests, ir.toMap())
10198
}
10299
obj["ip_restrictions"] = ipRests
103100

104101
var endpoints []map[string]interface{}
105-
for _, e := range v.Endpoints {
102+
for _, e := range r.Endpoints {
106103
endpoints = append(endpoints, e.ToMap())
107104
}
108105
obj["endpoints"] = endpoints
109106

110-
obj["flavor"] = v.Flavor
111-
obj["kafka_rest_api"] = v.RestApi
112-
obj["maintenance_time"] = v.MaintenanceTime
113-
obj["network_type"] = v.NetworkType
107+
obj["flavor"] = r.Flavor
108+
obj["kafka_rest_api"] = r.RestAPI
109+
obj["kafka_schema_registry"] = r.SchemaRegistry
110+
obj["maintenance_time"] = r.MaintenanceTime
111+
obj["network_type"] = r.NetworkType
114112

115113
var nodes []map[string]interface{}
116-
for i := 0; i < v.NodeNumber; i++ {
114+
for i := 0; i < r.NodeNumber; i++ {
117115
node := CloudProjectDatabaseNodes{
118-
Region: v.Region,
119-
NetworkId: v.NetworkId,
120-
SubnetId: v.SubnetId,
116+
Region: r.Region,
117+
NetworkId: r.NetworkID,
118+
SubnetId: r.SubnetID,
121119
}
122120
nodes = append(nodes, node.ToMap())
123121
}
124122
obj["nodes"] = nodes
125123

126-
obj["opensearch_acls_enabled"] = v.AclsEnabled
127-
obj["plan"] = v.Plan
128-
obj["status"] = v.Status
129-
obj["version"] = v.Version
130-
obj["disk_size"] = v.Disk.Size
131-
obj["disk_type"] = v.Disk.Type
132-
obj["advanced_configuration"] = v.AdvancedConfiguration
124+
obj["opensearch_acls_enabled"] = r.AclsEnabled
125+
obj["plan"] = r.Plan
126+
obj["status"] = r.Status
127+
obj["version"] = r.Version
128+
obj["disk_size"] = r.Disk.Size
129+
obj["disk_type"] = r.Disk.Type
130+
obj["advanced_configuration"] = r.AdvancedConfiguration
133131

134132
return obj
135133
}
@@ -185,7 +183,7 @@ func (v CloudProjectDatabaseNodes) ToMap() map[string]interface{} {
185183
}
186184

187185
type CloudProjectDatabaseCreateOpts struct {
188-
Backups CloudProjectDatabaseBackups `json:"backups,omitempty"`
186+
Backups *CloudProjectDatabaseBackups `json:"backups,omitempty"`
189187
Description string `json:"description,omitempty"`
190188
Disk CloudProjectDatabaseDisk `json:"disk,omitempty"`
191189
IPRestrictions []CloudProjectDatabaseIPRestriction `json:"ipRestrictions,omitempty"`
@@ -212,7 +210,7 @@ type CloudProjectDatabaseNodesPattern struct {
212210
Region string `json:"region"`
213211
}
214212

215-
func (opts *CloudProjectDatabaseCreateOpts) FromResource(d *schema.ResourceData) (*CloudProjectDatabaseCreateOpts, error) {
213+
func (opts *CloudProjectDatabaseCreateOpts) fromResource(d *schema.ResourceData) (*CloudProjectDatabaseCreateOpts, error) {
216214
opts.Description = d.Get("description").(string)
217215
opts.Plan = d.Get("plan").(string)
218216

@@ -251,33 +249,39 @@ func (opts *CloudProjectDatabaseCreateOpts) FromResource(d *schema.ResourceData)
251249
if err != nil {
252250
return nil, err
253251
}
252+
time := d.Get("backup_time").(string)
254253

255-
opts.Backups = CloudProjectDatabaseBackups{
256-
Regions: regions,
257-
Time: d.Get("backup_time").(string),
254+
if len(regions) != 0 || time != "" {
255+
opts.Backups = &CloudProjectDatabaseBackups{
256+
Regions: regions,
257+
Time: time,
258+
}
258259
}
260+
259261
return opts, nil
260262
}
261263

262264
type CloudProjectDatabaseUpdateOpts struct {
263265
AclsEnabled bool `json:"aclsEnabled,omitempty"`
264-
Backups CloudProjectDatabaseBackups `json:"backups,omitempty"`
266+
Backups *CloudProjectDatabaseBackups `json:"backups,omitempty"`
265267
Description string `json:"description,omitempty"`
266268
Disk CloudProjectDatabaseDisk `json:"disk,omitempty"`
267269
Flavor string `json:"flavor,omitempty"`
268270
IPRestrictions []CloudProjectDatabaseIPRestriction `json:"ipRestrictions,omitempty"`
269271
Plan string `json:"plan,omitempty"`
270-
RestApi bool `json:"restApi,omitempty"`
272+
RestAPI bool `json:"restApi,omitempty"`
273+
SchemaRegistry bool `json:"schemaRegistry,omitempty"`
271274
Version string `json:"version,omitempty"`
272275
}
273276

274-
func (opts *CloudProjectDatabaseUpdateOpts) FromResource(d *schema.ResourceData) (*CloudProjectDatabaseUpdateOpts, error) {
277+
func (opts *CloudProjectDatabaseUpdateOpts) fromResource(d *schema.ResourceData) (*CloudProjectDatabaseUpdateOpts, error) {
275278
engine := d.Get("engine").(string)
276279
if engine == "opensearch" {
277280
opts.AclsEnabled = d.Get("opensearch_acls_enabled").(bool)
278281
}
279282
if engine == "kafka" {
280-
opts.RestApi = d.Get("kafka_rest_api").(bool)
283+
opts.RestAPI = d.Get("kafka_rest_api").(bool)
284+
opts.SchemaRegistry = d.Get("kafka_schema_registry").(bool)
281285
}
282286

283287
opts.Description = d.Get("description").(string)
@@ -301,10 +305,13 @@ func (opts *CloudProjectDatabaseUpdateOpts) FromResource(d *schema.ResourceData)
301305
if err != nil {
302306
return nil, err
303307
}
308+
time := d.Get("backup_time").(string)
304309

305-
opts.Backups = CloudProjectDatabaseBackups{
306-
Regions: regions,
307-
Time: d.Get("backup_time").(string),
310+
if engine != "kafka" && (len(regions) != 0 || time != "") {
311+
opts.Backups = &CloudProjectDatabaseBackups{
312+
Regions: regions,
313+
Time: time,
314+
}
308315
}
309316

310317
return opts, nil

Diff for: website/docs/d/cloud_project_database.html.markdown

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ The following attributes are exported:
6161
* `ip` - Authorized IP
6262
* `status` - Current status of the IP restriction.
6363
* `kafka_rest_api` - Defines whether the REST API is enabled on a kafka cluster.
64+
* `kafka_schema_registry` - Defines whether the schema registry is enabled on a Kafka cluster
6465
* `maintenance_time` - Time on which maintenances can start every day.
6566
* `network_type` - Type of network of the cluster.
6667
* `nodes` - List of nodes object.

0 commit comments

Comments
 (0)