Skip to content

Commit

Permalink
Merge pull request #74 from volcengine/mongodb_fix
Browse files Browse the repository at this point in the history
Mongodb fix
  • Loading branch information
xuyaming0800 authored Mar 24, 2023
2 parents e0851b7 + bb9d449 commit f5e92c1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 18 deletions.
2 changes: 1 addition & 1 deletion common/common_volcengine_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package common

const (
TerraformProviderName = "terraform-provider-volcengine"
TerraformProviderVersion = "0.0.62"
TerraformProviderVersion = "0.0.63"
)
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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.",
},
Expand Down
32 changes: 24 additions & 8 deletions volcengine/mongodb/instance/service_volcengine_mongodb_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand All @@ -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)
})
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/mongodb_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.

Expand Down

0 comments on commit f5e92c1

Please sign in to comment.