Skip to content

Commit 739cc15

Browse files
committed
add
1 parent 578de1d commit 739cc15

File tree

3 files changed

+70
-21
lines changed

3 files changed

+70
-21
lines changed

tencentcloud/services/postgresql/resource_tc_postgresql_instance.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ func ResourceTencentCloudPostgresqlInstance() *schema.Resource {
166166
},
167167
"root_user": {
168168
Type: schema.TypeString,
169-
ForceNew: true,
170169
Optional: true,
171170
Default: "root",
172171
Description: "Instance root account name. This parameter is optional, Default value is `root`.",
@@ -1008,6 +1007,13 @@ func resourceTencentCloudPostgresqlInstanceUpdate(d *schema.ResourceData, meta i
10081007
return err
10091008
}
10101009

1010+
immutableArgs := []string{"root_user"}
1011+
for _, v := range immutableArgs {
1012+
if d.HasChange(v) {
1013+
return fmt.Errorf("argument `%s` cannot be changed", v)
1014+
}
1015+
}
1016+
10111017
if d.HasChange("period") && !d.HasChange("charge_type") {
10121018
return fmt.Errorf("The `period` field can be changed only when updating the charge type from `POSTPAID_BY_HOUR` to `PREPAID`.")
10131019
}

tencentcloud/services/postgresql/service_tencentcloud_postgresql.go

Lines changed: 62 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import (
55
"errors"
66
"fmt"
77
"log"
8+
"sort"
89
"strconv"
10+
"strings"
911
"time"
1012

1113
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
@@ -824,33 +826,74 @@ func (me *PostgresqlService) CheckDBInstanceStatus(ctx context.Context, instance
824826

825827
func (me *PostgresqlService) DescribeRootUser(ctx context.Context, instanceId string) (accounts []*postgresql.AccountInfo, errRet error) {
826828
logId := tccommon.GetLogId(ctx)
827-
orderBy := "createTime"
828-
orderByType := "asc"
829-
830829
request := postgresql.NewDescribeAccountsRequest()
831830
request.DBInstanceId = &instanceId
832-
request.OrderBy = &orderBy
833-
request.OrderByType = &orderByType
834-
request.Offset = helper.Int64(0)
835-
request.Limit = helper.Int64(100)
831+
request.OrderByType = helper.String("asc")
832+
request.OrderBy = helper.String("createTime")
833+
836834
var response *postgresql.DescribeAccountsResponse
837-
errRet = resource.Retry(2*tccommon.ReadRetryTimeout, func() *resource.RetryError {
838-
response, errRet = me.client.UsePostgresqlClient().DescribeAccounts(request)
835+
var tmpList []*postgresql.AccountInfo
836+
837+
var offset, limit int64 = 0, 100
838+
839+
for {
840+
request.Offset = &offset
841+
request.Limit = &limit
842+
ratelimit.Check(request.GetAction())
843+
errRet = resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
844+
result, e := me.client.UsePostgresqlClient().DescribeAccounts(request)
845+
if e != nil {
846+
log.Printf("[CRITAL]%s describe account failed, reason: %v", logId, e)
847+
return tccommon.RetryError(e)
848+
}
849+
850+
if result == nil || result.Response == nil || result.Response.Details == nil {
851+
errRet = fmt.Errorf("TencentCloud SDK return nil response, %+v, %s", result, request.GetAction())
852+
}
853+
854+
response = result
855+
return nil
856+
})
857+
839858
if errRet != nil {
840-
log.Printf("[CRITAL]%s describe account failed, reason: %v", logId, errRet)
841-
return tccommon.RetryError(errRet)
859+
return nil, errRet
842860
}
843-
return nil
844-
})
845-
if errRet != nil {
846-
return nil, errRet
861+
862+
tmpList = append(tmpList, response.Response.Details...)
863+
if len(response.Response.Details) < int(limit) {
864+
break
865+
}
866+
867+
offset += limit
847868
}
848-
if response == nil || response.Response == nil || response.Response.Details == nil {
849-
errRet = fmt.Errorf("TencentCloud SDK return nil response, %+v, %s", response, request.GetAction())
850-
} else {
851-
accounts = response.Response.Details
869+
870+
for _, item := range tmpList {
871+
if item.CreateTime != nil && strings.Contains(*item.CreateTime, "0000-00-00") {
872+
continue
873+
}
874+
875+
accounts = append(accounts, item)
852876
}
853877

878+
sort.Slice(accounts, func(i, j int) bool {
879+
timeStrI := accounts[i].CreateTime
880+
timeStrJ := accounts[j].CreateTime
881+
882+
timeI, errI := time.Parse(tccommon.TENCENTCLOUD_COMMON_TIME_LAYOUT, *timeStrI)
883+
if errI != nil {
884+
fmt.Printf("Error parsing time string %s: %v\n", *timeStrI, errI)
885+
return false
886+
}
887+
888+
timeJ, errJ := time.Parse(tccommon.TENCENTCLOUD_COMMON_TIME_LAYOUT, *timeStrJ)
889+
if errJ != nil {
890+
fmt.Printf("Error parsing time string %s: %v\n", *timeStrJ, errJ)
891+
return false
892+
}
893+
894+
return timeI.Before(timeJ)
895+
})
896+
854897
return accounts, errRet
855898
}
856899

website/docs/r/postgresql_instance.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ The following arguments are supported:
326326
* `period` - (Optional, Int) Specify Prepaid period in month. Default `1`. Values: `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `10`, `11`, `12`, `24`, `36`. This field is valid only when creating a `PREPAID` type instance, or updating the charge type from `POSTPAID_BY_HOUR` to `PREPAID`.
327327
* `project_id` - (Optional, Int) Project id, default value is `0`.
328328
* `public_access_switch` - (Optional, Bool) Indicates whether to enable the access to an instance from public network or not.
329-
* `root_user` - (Optional, String, ForceNew) Instance root account name. This parameter is optional, Default value is `root`.
329+
* `root_user` - (Optional, String) Instance root account name. This parameter is optional, Default value is `root`.
330330
* `security_groups` - (Optional, Set: [`String`]) ID of security group. If both vpc_id and subnet_id are not set, this argument should not be set either.
331331
* `tags` - (Optional, Map) The available tags within this postgresql.
332332
* `voucher_ids` - (Optional, List: [`String`]) Specify Voucher Ids if `auto_voucher` was `1`, only support using 1 vouchers for now.

0 commit comments

Comments
 (0)