From fc0167b7e3d1bf93af1b5beded1768025c355352 Mon Sep 17 00:00:00 2001 From: xuyaming0800 Date: Fri, 24 Mar 2023 19:11:50 +0800 Subject: [PATCH 1/3] bugfix: fix mongo password --- .../resource_volcengine_mongodb_instance.go | 17 +++++----- .../service_volcengine_mongodb_instance.go | 32 ++++++++++++++----- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/volcengine/mongodb/instance/resource_volcengine_mongodb_instance.go b/volcengine/mongodb/instance/resource_volcengine_mongodb_instance.go index 5e568314..e858102c 100644 --- a/volcengine/mongodb/instance/resource_volcengine_mongodb_instance.go +++ b/volcengine/mongodb/instance/resource_volcengine_mongodb_instance.go @@ -77,7 +77,7 @@ func ResourceVolcengineMongoDBInstance() *schema.Resource { "mongos_node_number": { Type: schema.TypeInt, Optional: true, - Computed: true, + Default: 2, Description: "The mongos node number of shard cluster,value range is `2~23`,this parameter is required when `InstanceType` is `ShardedCluster`.", }, "shard_number": { @@ -106,15 +106,16 @@ func ResourceVolcengineMongoDBInstance() *schema.Resource { }, Description: "The subnet id of instance.", }, - // "super_account_name": { - // Type: schema.TypeString, - // Required: true, - // ValidateFunc: validation.StringInSlice([]string{"root"}, false), - // Description: "The name of database account,must be `root`.", - // }, + //"super_account_name": { + // Type: schema.TypeString, + // ValidateFunc: validation.StringInSlice([]string{"root"}, false), + // Default: "root", + // Optional: true, + // Description: "The name of database account,must be `root`.", + //}, "super_account_password": { Type: schema.TypeString, - Required: true, + Optional: true, Sensitive: true, Description: "The password of database account.", }, diff --git a/volcengine/mongodb/instance/service_volcengine_mongodb_instance.go b/volcengine/mongodb/instance/service_volcengine_mongodb_instance.go index b73e502a..bc94df3a 100644 --- a/volcengine/mongodb/instance/service_volcengine_mongodb_instance.go +++ b/volcengine/mongodb/instance/service_volcengine_mongodb_instance.go @@ -460,8 +460,9 @@ func (s *VolcengineMongoDBInstanceService) ModifyResource(resourceData *schema.R ConvertMode: ve.RequestConvertIgnore, ContentType: ve.ContentTypeJson, BeforeCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (bool, error) { - (*call.SdkParam)["InstanceId"] = d.Get("instance_id") - (*call.SdkParam)["AccountName"] = d.Get("super_account_name") + (*call.SdkParam)["InstanceId"] = d.Id() + //暂时写死 当前不支持这个字段 只能是root + (*call.SdkParam)["AccountName"] = "root" (*call.SdkParam)["AccountPassword"] = d.Get("super_account_password") return true, nil }, @@ -481,21 +482,36 @@ func (s *VolcengineMongoDBInstanceService) ModifyResource(resourceData *schema.R return callbacks } -func (s *VolcengineMongoDBInstanceService) RemoveResource(resourceData *schema.ResourceData, resource *schema.Resource) []ve.Callback { +func (s *VolcengineMongoDBInstanceService) RemoveResource(resourceData *schema.ResourceData, r *schema.Resource) []ve.Callback { + callback := ve.Callback{ Call: ve.SdkCall{ Action: "DeleteDBInstance", ConvertMode: ve.RequestConvertIgnore, - BeforeCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (bool, error) { - (*call.SdkParam)["InstanceId"] = d.Id() - return true, nil + SdkParam: &map[string]interface{}{ + "InstanceId": resourceData.Id(), }, ExecuteCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (*map[string]interface{}, error) { logger.Debug(logger.ReqFormat, call.Action, call.SdkParam) return s.Client.UniversalClient.DoCall(getUniversalInfo(call.Action), call.SdkParam) }, - AfterCall: func(d *schema.ResourceData, client *ve.SdkClient, resp *map[string]interface{}, call ve.SdkCall) error { - return ve.CheckResourceUtilRemoved(d, s.ReadResource, 3*time.Minute) + CallError: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall, baseErr error) error { + //出现错误后重试 + return resource.Retry(15*time.Minute, func() *resource.RetryError { + _, callErr := s.ReadResource(d, "") + if callErr != nil { + if ve.ResourceNotFoundError(callErr) { + return nil + } else { + return resource.NonRetryableError(fmt.Errorf("error on reading mongodb on delete %q, %w", d.Id(), callErr)) + } + } + _, callErr = call.ExecuteCall(d, client, call) + if callErr == nil { + return nil + } + return resource.RetryableError(callErr) + }) }, }, } From ce93ab7952c8139797a8414e67b9a777bc664094 Mon Sep 17 00:00:00 2001 From: xuyaming0800 Date: Fri, 24 Mar 2023 19:13:31 +0800 Subject: [PATCH 2/3] bugfix: fix mongo password --- common/common_volcengine_version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/common_volcengine_version.go b/common/common_volcengine_version.go index 1792b031..0543f049 100644 --- a/common/common_volcengine_version.go +++ b/common/common_volcengine_version.go @@ -2,5 +2,5 @@ package common const ( TerraformProviderName = "terraform-provider-volcengine" - TerraformProviderVersion = "0.0.62" + TerraformProviderVersion = "0.0.63" ) From bb9d4498f2fd853949d5f2b74bd5f9abd33f3eda Mon Sep 17 00:00:00 2001 From: xuyaming0800 Date: Fri, 24 Mar 2023 19:14:43 +0800 Subject: [PATCH 3/3] bugfix: fix mongo password --- website/docs/r/mongodb_instance.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/mongodb_instance.html.markdown b/website/docs/r/mongodb_instance.html.markdown index e9de921e..22dc90a7 100644 --- a/website/docs/r/mongodb_instance.html.markdown +++ b/website/docs/r/mongodb_instance.html.markdown @@ -37,7 +37,6 @@ The following arguments are supported: * `node_spec` - (Required) The spec of node. * `storage_space_gb` - (Required) The total storage space of a replica set instance, or the storage space of a single shard in a sharded cluster, in GiB. * `subnet_id` - (Required, ForceNew) The subnet id of instance. -* `super_account_password` - (Required) The password of database account. * `auto_renew` - (Optional) Whether to enable automatic renewal. * `charge_type` - (Optional) The charge type of instance,valid value contains `Prepaid` or `PostPaid`. * `instance_name` - (Optional) The instance name. @@ -48,6 +47,7 @@ The following arguments are supported: * `period` - (Optional) The instance purchase duration,the value range is `1~3` when `PeriodUtil` is `Year`,the value range is `1~9` when `PeriodUtil` is `Month`,this parameter is required when `ChargeType` is `Prepaid`. * `project_name` - (Optional) The project name to which the instance belongs. * `shard_number` - (Optional) The number of shards in shard cluster,value range is `2~23`,this parameter is required when `InstanceType` is `ShardedCluster`. +* `super_account_password` - (Optional) The password of database account. * `vpc_id` - (Optional) The vpc ID. * `zone_id` - (Optional) The zone ID of instance.