Skip to content

Commit 48da009

Browse files
tongyimingmikatong
and
mikatong
authored
fix(mongodb): [122484279]support in_maintenance (#3257)
* support in_maintenance * add changelog * update --------- Co-authored-by: mikatong <[email protected]>
1 parent fb2e487 commit 48da009

11 files changed

+135
-63
lines changed

.changelog/3257.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_mongodb_instance: support in_maintenance
3+
```
4+
5+
```release-note:enhancement
6+
resource/tencentcloud_mongodb_readonly_instance: support in_maintenance
7+
```
8+
9+
```release-note:enhancement
10+
resource/tencentcloud_mongodb_standby_instance: support in_maintenance
11+
```
12+
13+
```release-note:enhancement
14+
resource/tencentcloud_mongodb_sharding_instance: support in_maintenance
15+
```

tencentcloud/services/mongodb/extension_mongodb.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,14 @@ func TencentMongodbBasicInfo() map[string]*schema.Schema {
200200
Default: 0,
201201
Description: "Auto renew flag. Valid values are `0`(NOTIFY_AND_MANUAL_RENEW), `1`(NOTIFY_AND_AUTO_RENEW) and `2`(DISABLE_NOTIFY_AND_MANUAL_RENEW). Default value is `0`. Note: only works for PREPAID instance. Only supports`0` and `1` for creation.",
202202
},
203+
"in_maintenance": {
204+
Type: schema.TypeInt,
205+
Optional: true,
206+
Description: "Switch time for instance configuration changes.\n" +
207+
" - 0: When the adjustment is completed, perform the configuration task immediately. Default is 0.\n" +
208+
" - 1: Perform reconfiguration tasks within the maintenance time window.\n" +
209+
"Note: Adjusting the number of nodes and slices does not support changes within the maintenance window.",
210+
},
203211
// Computed
204212
"status": {
205213
Type: schema.TypeInt,

tencentcloud/services/mongodb/resource_tc_mongodb_instance.go

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,11 @@ func resourceTencentCloudMongodbInstanceUpdate(d *schema.ResourceData, meta inte
553553
removeNodeList := v.([]interface{})
554554
params["remove_node_list"] = removeNodeList
555555
}
556+
var inMaintenance int
557+
if v, ok := d.GetOkExists("in_maintenance"); ok {
558+
inMaintenance = v.(int)
559+
params["in_maintenance"] = v.(int)
560+
}
556561
dealId, err := mongodbService.UpgradeInstance(ctx, instanceId, memory, volume, params)
557562
if err != nil {
558563
return err
@@ -562,26 +567,27 @@ func resourceTencentCloudMongodbInstanceUpdate(d *schema.ResourceData, meta inte
562567
return fmt.Errorf("deal id is empty")
563568
}
564569

565-
errUpdate := resource.Retry(20*tccommon.ReadRetryTimeout, func() *resource.RetryError {
566-
dealResponseParams, err := mongodbService.DescribeDBInstanceDeal(ctx, dealId)
567-
if err != nil {
568-
if sdkError, ok := err.(*errors.TencentCloudSDKError); ok {
569-
if sdkError.Code == "InvalidParameter" && sdkError.Message == "deal resource not found." {
570-
return resource.RetryableError(err)
570+
if inMaintenance == 0 {
571+
errUpdate := resource.Retry(20*tccommon.ReadRetryTimeout, func() *resource.RetryError {
572+
dealResponseParams, err := mongodbService.DescribeDBInstanceDeal(ctx, dealId)
573+
if err != nil {
574+
if sdkError, ok := err.(*errors.TencentCloudSDKError); ok {
575+
if sdkError.Code == "InvalidParameter" && sdkError.Message == "deal resource not found." {
576+
return resource.RetryableError(err)
577+
}
571578
}
579+
return resource.NonRetryableError(err)
572580
}
573-
return resource.NonRetryableError(err)
574-
}
575581

576-
if *dealResponseParams.Status != MONGODB_STATUS_DELIVERY_SUCCESS {
577-
return resource.RetryableError(fmt.Errorf("mongodb status is not delivery success"))
582+
if *dealResponseParams.Status != MONGODB_STATUS_DELIVERY_SUCCESS {
583+
return resource.RetryableError(fmt.Errorf("mongodb status is not delivery success"))
584+
}
585+
return nil
586+
})
587+
if errUpdate != nil {
588+
return errUpdate
578589
}
579-
return nil
580-
})
581-
if errUpdate != nil {
582-
return errUpdate
583590
}
584-
585591
}
586592

587593
if d.HasChange("instance_name") {

tencentcloud/services/mongodb/resource_tc_mongodb_readonly_instance.go

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -448,32 +448,40 @@ func resourceTencentCloudMongodbReadOnlyInstanceUpdate(d *schema.ResourceData, m
448448
if d.HasChange("memory") || d.HasChange("volume") {
449449
memory := d.Get("memory").(int)
450450
volume := d.Get("volume").(int)
451-
dealId, err := mongodbService.UpgradeInstance(ctx, instanceId, memory, volume, nil)
451+
params := make(map[string]interface{})
452+
var inMaintenance int
453+
if v, ok := d.GetOkExists("in_maintenance"); ok {
454+
inMaintenance = v.(int)
455+
params["in_maintenance"] = v.(int)
456+
}
457+
dealId, err := mongodbService.UpgradeInstance(ctx, instanceId, memory, volume, params)
452458
if err != nil {
453459
return err
454460
}
455461
if dealId == "" {
456462
return fmt.Errorf("deal id is empty")
457463
}
458464

459-
errUpdate := resource.Retry(20*tccommon.ReadRetryTimeout, func() *resource.RetryError {
460-
dealResponseParams, err := mongodbService.DescribeDBInstanceDeal(ctx, dealId)
461-
if err != nil {
462-
if sdkError, ok := err.(*sdkErrors.TencentCloudSDKError); ok {
463-
if sdkError.Code == "InvalidParameter" && sdkError.Message == "deal resource not found." {
464-
return resource.RetryableError(err)
465+
if inMaintenance == 0 {
466+
errUpdate := resource.Retry(20*tccommon.ReadRetryTimeout, func() *resource.RetryError {
467+
dealResponseParams, err := mongodbService.DescribeDBInstanceDeal(ctx, dealId)
468+
if err != nil {
469+
if sdkError, ok := err.(*sdkErrors.TencentCloudSDKError); ok {
470+
if sdkError.Code == "InvalidParameter" && sdkError.Message == "deal resource not found." {
471+
return resource.RetryableError(err)
472+
}
465473
}
474+
return resource.NonRetryableError(err)
466475
}
467-
return resource.NonRetryableError(err)
468-
}
469476

470-
if *dealResponseParams.Status != MONGODB_STATUS_DELIVERY_SUCCESS {
471-
return resource.RetryableError(fmt.Errorf("mongodb status is not delivery success"))
477+
if *dealResponseParams.Status != MONGODB_STATUS_DELIVERY_SUCCESS {
478+
return resource.RetryableError(fmt.Errorf("mongodb status is not delivery success"))
479+
}
480+
return nil
481+
})
482+
if errUpdate != nil {
483+
return errUpdate
472484
}
473-
return nil
474-
})
475-
if errUpdate != nil {
476-
return errUpdate
477485
}
478486

479487
}

tencentcloud/services/mongodb/resource_tc_mongodb_sharding_instance.go

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -468,32 +468,40 @@ func resourceMongodbShardingInstanceUpdate(d *schema.ResourceData, meta interfac
468468
if d.HasChange("memory") || d.HasChange("volume") {
469469
memory := d.Get("memory").(int)
470470
volume := d.Get("volume").(int)
471-
_, err := mongodbService.UpgradeInstance(ctx, instanceId, memory, volume, nil)
471+
params := make(map[string]interface{})
472+
473+
var inMaintenance int
474+
if v, ok := d.GetOkExists("in_maintenance"); ok {
475+
inMaintenance = v.(int)
476+
params["in_maintenance"] = v.(int)
477+
}
478+
_, err := mongodbService.UpgradeInstance(ctx, instanceId, memory, volume, params)
472479
if err != nil {
473480
return err
474481
}
475482

476483
// it will take time to wait for memory and volume change even describe request succeeded even the status returned in describe response is running
477-
errUpdate := resource.Retry(20*tccommon.ReadRetryTimeout, func() *resource.RetryError {
478-
infos, has, e := mongodbService.DescribeInstanceById(ctx, instanceId)
479-
if e != nil {
480-
return resource.NonRetryableError(e)
481-
}
482-
if !has {
483-
return resource.NonRetryableError(fmt.Errorf("[CRITAL]%s updating mongodb sharding instance failed, instance doesn't exist", logId))
484-
}
484+
if inMaintenance == 0 {
485+
errUpdate := resource.Retry(20*tccommon.ReadRetryTimeout, func() *resource.RetryError {
486+
infos, has, e := mongodbService.DescribeInstanceById(ctx, instanceId)
487+
if e != nil {
488+
return resource.NonRetryableError(e)
489+
}
490+
if !has {
491+
return resource.NonRetryableError(fmt.Errorf("[CRITAL]%s updating mongodb sharding instance failed, instance doesn't exist", logId))
492+
}
485493

486-
memoryDes := *infos.Memory / 1024 / (*infos.ReplicationSetNum)
487-
volumeDes := *infos.Volume / 1024 / (*infos.ReplicationSetNum)
488-
if memory != int(memoryDes) || volume != int(volumeDes) {
489-
return resource.RetryableError(fmt.Errorf("[CRITAL] updating mongodb sharding instance, current memory and volume values: %d, %d, waiting for them becoming new value: %d, %d", memoryDes, volumeDes, d.Get("memory").(int), d.Get("volume").(int)))
494+
memoryDes := *infos.Memory / 1024 / (*infos.ReplicationSetNum)
495+
volumeDes := *infos.Volume / 1024 / (*infos.ReplicationSetNum)
496+
if memory != int(memoryDes) || volume != int(volumeDes) {
497+
return resource.RetryableError(fmt.Errorf("[CRITAL] updating mongodb sharding instance, current memory and volume values: %d, %d, waiting for them becoming new value: %d, %d", memoryDes, volumeDes, d.Get("memory").(int), d.Get("volume").(int)))
498+
}
499+
return nil
500+
})
501+
if errUpdate != nil {
502+
return errUpdate
490503
}
491-
return nil
492-
})
493-
if errUpdate != nil {
494-
return errUpdate
495504
}
496-
497505
}
498506

499507
if d.HasChange("instance_name") {

tencentcloud/services/mongodb/resource_tc_mongodb_standby_instance.go

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -403,32 +403,40 @@ func resourceTencentCloudMongodbStandbyInstanceUpdate(d *schema.ResourceData, me
403403
if d.HasChange("memory") || d.HasChange("volume") {
404404
memory := d.Get("memory").(int)
405405
volume := d.Get("volume").(int)
406-
dealId, err := mongodbService.UpgradeInstance(ctx, instanceId, memory, volume, nil)
406+
params := make(map[string]interface{})
407+
var inMaintenance int
408+
if v, ok := d.GetOkExists("in_maintenance"); ok {
409+
inMaintenance = v.(int)
410+
params["in_maintenance"] = v.(int)
411+
}
412+
dealId, err := mongodbService.UpgradeInstance(ctx, instanceId, memory, volume, params)
407413
if err != nil {
408414
return err
409415
}
410416
if dealId == "" {
411417
return fmt.Errorf("deal id is empty")
412418
}
413419

414-
errUpdate := resource.Retry(20*tccommon.ReadRetryTimeout, func() *resource.RetryError {
415-
dealResponseParams, err := mongodbService.DescribeDBInstanceDeal(ctx, dealId)
416-
if err != nil {
417-
if sdkError, ok := err.(*sdkErrors.TencentCloudSDKError); ok {
418-
if sdkError.Code == "InvalidParameter" && sdkError.Message == "deal resource not found." {
419-
return resource.RetryableError(err)
420+
if inMaintenance == 0 {
421+
errUpdate := resource.Retry(20*tccommon.ReadRetryTimeout, func() *resource.RetryError {
422+
dealResponseParams, err := mongodbService.DescribeDBInstanceDeal(ctx, dealId)
423+
if err != nil {
424+
if sdkError, ok := err.(*sdkErrors.TencentCloudSDKError); ok {
425+
if sdkError.Code == "InvalidParameter" && sdkError.Message == "deal resource not found." {
426+
return resource.RetryableError(err)
427+
}
420428
}
429+
return resource.NonRetryableError(err)
421430
}
422-
return resource.NonRetryableError(err)
423-
}
424431

425-
if *dealResponseParams.Status != MONGODB_STATUS_DELIVERY_SUCCESS {
426-
return resource.RetryableError(fmt.Errorf("mongodb status is not delivery success"))
432+
if *dealResponseParams.Status != MONGODB_STATUS_DELIVERY_SUCCESS {
433+
return resource.RetryableError(fmt.Errorf("mongodb status is not delivery success"))
434+
}
435+
return nil
436+
})
437+
if errUpdate != nil {
438+
return errUpdate
427439
}
428-
return nil
429-
})
430-
if errUpdate != nil {
431-
return errUpdate
432440
}
433441

434442
}

tencentcloud/services/mongodb/service_tencentcloud_mongodb.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ func (me *MongodbService) UpgradeInstance(ctx context.Context, instanceId string
190190
})
191191
}
192192
}
193+
if v, ok := params["in_maintenance"]; ok {
194+
request.InMaintenance = helper.IntUint64(v.(int))
195+
}
193196
var response *mongodb.ModifyDBInstanceSpecResponse
194197
tradeError := false
195198
err := resource.Retry(6*tccommon.WriteRetryTimeout, func() *resource.RetryError {

website/docs/r/mongodb_instance.html.markdown

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ The following arguments are supported:
4747
- Basic network cannot be selected.
4848
* `charge_type` - (Optional, String, ForceNew) The charge type of instance. Valid values are `PREPAID` and `POSTPAID_BY_HOUR`. Default value is `POSTPAID_BY_HOUR`. Note: TencentCloud International only supports `POSTPAID_BY_HOUR`. Caution that update operation on this field will delete old instances and create new one with new charge type.
4949
* `hidden_zone` - (Optional, String) The availability zone to which the Hidden node belongs. This parameter is required in cross-AZ instance deployment.
50+
* `in_maintenance` - (Optional, Int) Switch time for instance configuration changes.
51+
- 0: When the adjustment is completed, perform the configuration task immediately. Default is 0.
52+
- 1: Perform reconfiguration tasks within the maintenance time window.
53+
Note: Adjusting the number of nodes and slices does not support changes within the maintenance window.
5054
* `maintenance_end` - (Optional, String) Maintenance window end time.
5155
- The value range is any full point or half point from `00:00-23:00`, and the maintenance time duration is at least 30 minutes and at most 3 hours.
5256
- The end time must be based on the start time backwards.

website/docs/r/mongodb_readonly_instance.html.markdown

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ The following arguments are supported:
7171
* `volume` - (Required, Int) Disk size. The minimum value is 25, and unit is GB. Memory and volume must be upgraded or degraded simultaneously.
7272
* `auto_renew_flag` - (Optional, Int) Auto renew flag. Valid values are `0`(NOTIFY_AND_MANUAL_RENEW), `1`(NOTIFY_AND_AUTO_RENEW) and `2`(DISABLE_NOTIFY_AND_MANUAL_RENEW). Default value is `0`. Note: only works for PREPAID instance. Only supports`0` and `1` for creation.
7373
* `charge_type` - (Optional, String, ForceNew) The charge type of instance. Valid values are `PREPAID` and `POSTPAID_BY_HOUR`. Default value is `POSTPAID_BY_HOUR`. Note: TencentCloud International only supports `POSTPAID_BY_HOUR`. Caution that update operation on this field will delete old instances and create new one with new charge type.
74+
* `in_maintenance` - (Optional, Int) Switch time for instance configuration changes.
75+
- 0: When the adjustment is completed, perform the configuration task immediately. Default is 0.
76+
- 1: Perform reconfiguration tasks within the maintenance time window.
77+
Note: Adjusting the number of nodes and slices does not support changes within the maintenance window.
7478
* `mongos_cpu` - (Optional, Int) Number of mongos cpu.
7579
* `mongos_memory` - (Optional, Int) Mongos memory size in GB.
7680
* `mongos_node_num` - (Optional, Int) Number of mongos.

website/docs/r/mongodb_sharding_instance.html.markdown

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ The following arguments are supported:
5353
- Basic network cannot be selected.
5454
* `charge_type` - (Optional, String, ForceNew) The charge type of instance. Valid values are `PREPAID` and `POSTPAID_BY_HOUR`. Default value is `POSTPAID_BY_HOUR`. Note: TencentCloud International only supports `POSTPAID_BY_HOUR`. Caution that update operation on this field will delete old instances and create new one with new charge type.
5555
* `hidden_zone` - (Optional, String) The availability zone to which the Hidden node belongs. This parameter is required in cross-AZ instance deployment.
56+
* `in_maintenance` - (Optional, Int) Switch time for instance configuration changes.
57+
- 0: When the adjustment is completed, perform the configuration task immediately. Default is 0.
58+
- 1: Perform reconfiguration tasks within the maintenance time window.
59+
Note: Adjusting the number of nodes and slices does not support changes within the maintenance window.
5660
* `mongos_cpu` - (Optional, Int) Number of mongos cpu.
5761
* `mongos_memory` - (Optional, Int) Mongos memory size in GB.
5862
* `mongos_node_num` - (Optional, Int) Number of mongos.

website/docs/r/mongodb_standby_instance.html.markdown

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ The following arguments are supported:
6666
* `volume` - (Required, Int) Disk size. The minimum value is 25, and unit is GB. Memory and volume must be upgraded or degraded simultaneously.
6767
* `auto_renew_flag` - (Optional, Int) Auto renew flag. Valid values are `0`(NOTIFY_AND_MANUAL_RENEW), `1`(NOTIFY_AND_AUTO_RENEW) and `2`(DISABLE_NOTIFY_AND_MANUAL_RENEW). Default value is `0`. Note: only works for PREPAID instance. Only supports`0` and `1` for creation.
6868
* `charge_type` - (Optional, String, ForceNew) The charge type of instance. Valid values are `PREPAID` and `POSTPAID_BY_HOUR`. Default value is `POSTPAID_BY_HOUR`. Note: TencentCloud International only supports `POSTPAID_BY_HOUR`. Caution that update operation on this field will delete old instances and create new one with new charge type.
69+
* `in_maintenance` - (Optional, Int) Switch time for instance configuration changes.
70+
- 0: When the adjustment is completed, perform the configuration task immediately. Default is 0.
71+
- 1: Perform reconfiguration tasks within the maintenance time window.
72+
Note: Adjusting the number of nodes and slices does not support changes within the maintenance window.
6973
* `prepaid_period` - (Optional, Int) The tenancy (time unit is month) of the prepaid instance. Valid values are 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 24, 36. NOTE: it only works when charge_type is set to `PREPAID`.
7074
* `project_id` - (Optional, Int) ID of the project which the instance belongs.
7175
* `security_groups` - (Optional, Set: [`String`]) ID of the security group.

0 commit comments

Comments
 (0)