Skip to content

Commit 8d9d9e8

Browse files
committed
to fit the SDK changes
1 parent c349fac commit 8d9d9e8

File tree

4 files changed

+19
-18
lines changed

4 files changed

+19
-18
lines changed

tencentcloud/data_source_tc_postgresql_instances.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ func dataSourceTencentCloudPostgresqlInstanceRead(d *schema.ResourceData, meta i
203203
listItem["public_access_switch"] = false
204204
listItem["charset"] = v.DBCharset
205205
listItem["public_access_host"] = ""
206+
206207
for _, netInfo := range v.DBInstanceNetInfo {
207208
if *netInfo.NetType == "public" {
208209
if *netInfo.Status == "opened" || *netInfo.Status == "1" {
@@ -211,12 +212,13 @@ func dataSourceTencentCloudPostgresqlInstanceRead(d *schema.ResourceData, meta i
211212
listItem["public_access_host"] = netInfo.Address
212213
listItem["public_access_port"] = netInfo.Port
213214
}
214-
if *netInfo.NetType == "private" {
215+
if (*netInfo.NetType == "private" || *netInfo.NetType == "inner") && *netInfo.Ip != "" {
215216
listItem["private_access_ip"] = netInfo.Ip
216217
listItem["private_access_port"] = netInfo.Port
217218
}
218219
}
219-
if *v.PayType == POSTGRESQL_PAYTYPE_PREPAID {
220+
221+
if *v.PayType == POSTGRESQL_PAYTYPE_PREPAID || *v.PayType == COMMON_PAYTYPE_PREPAID {
220222
listItem["charge_type"] = COMMON_PAYTYPE_PREPAID
221223
} else {
222224
listItem["charge_type"] = COMMON_PAYTYPE_POSTPAID

tencentcloud/data_source_tc_postgresql_instances_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ default = "ap-guangzhou-2"
4545
resource "tencentcloud_postgresql_instance" "test" {
4646
name = "tf_postsql_instance"
4747
availability_zone = var.availability_zone
48-
charge_type = "postpaid"
49-
vpc_id = "` + defaultVpcId + `"
50-
subnet_id = "subnet-pyio7yog"
48+
charge_type = "POSTPAID_BY_HOUR"
5149
engine_version = "9.3.5"
5250
root_password = "1qaA2k1wgvfa3ZZZ"
5351
charset = "UTF8"

tencentcloud/resource_tc_postgresql_instance.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func resourceTencentCloudPostgresqlInstance() *schema.Resource {
5757
"charge_type": {
5858
Type: schema.TypeString,
5959
Optional: true,
60-
Default: POSTGRESQL_PAYTYPE_POSTPAID,
60+
Default: COMMON_PAYTYPE_POSTPAID,
6161
ForceNew: true,
6262
ValidateFunc: validateAllowedStringValue(POSTGRESQL_PAYTYPE),
6363
Description: "Pay type of the postgresql instance. For now, only `POSTPAID_BY_HOUR` is valid.",
@@ -186,11 +186,14 @@ func resourceTencentCloudPostgresqlInstanceCreate(d *schema.ResourceData, meta i
186186
var period = 1
187187
//the sdk asks to set value with 1 when paytype is postpaid
188188

189-
if payType == COMMON_PAYTYPE_PREPAID {
190-
payType = POSTGRESQL_PAYTYPE_PREPAID
191-
} else {
192-
payType = POSTGRESQL_PAYTYPE_POSTPAID
193-
}
189+
/*
190+
if payType == COMMON_PAYTYPE_PREPAID {
191+
payType = POSTGRESQL_PAYTYPE_PREPAID
192+
} else {
193+
payType = POSTGRESQL_PAYTYPE_POSTPAID
194+
}
195+
196+
*/
194197

195198
var instanceId string
196199
var outErr, inErr error
@@ -443,12 +446,14 @@ func resourceTencentCloudPostgresqlInstanceRead(d *schema.ResourceData, meta int
443446
_ = d.Set("engine_version", instance.DBVersion)
444447
_ = d.Set("name", instance.DBInstanceName)
445448
_ = d.Set("charset", instance.DBCharset)
449+
_ = d.Set("charge_type", instance.PayType)
446450

447-
if *instance.PayType == POSTGRESQL_PAYTYPE_PREPAID {
451+
if *instance.PayType == POSTGRESQL_PAYTYPE_PREPAID || *instance.PayType == COMMON_PAYTYPE_PREPAID {
448452
_ = d.Set("charge_type", COMMON_PAYTYPE_PREPAID)
449453
} else {
450454
_ = d.Set("charge_type", COMMON_PAYTYPE_POSTPAID)
451455
}
456+
452457
//net status
453458
public_access_switch := false
454459
if len(instance.DBInstanceNetInfo) > 0 {
@@ -462,7 +467,8 @@ func resourceTencentCloudPostgresqlInstanceRead(d *schema.ResourceData, meta int
462467
_ = d.Set("public_access_host", v.Address)
463468
_ = d.Set("public_access_port", v.Port)
464469
}
465-
if *v.NetType == "private" {
470+
//private or inner will not appear at same time, private for instance with vpc
471+
if (*v.NetType == "private" || *v.NetType == "inner") && *v.Ip != "" {
466472
_ = d.Set("private_access_ip", v.Ip)
467473
_ = d.Set("private_access_port", v.Port)
468474
}

tencentcloud/service_tencentcloud_postgresql.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,6 @@ func (me *PostgresqlService) InitPostgresqlInstance(ctx context.Context, instanc
8181
if response == nil || response.Response == nil {
8282
errRet = fmt.Errorf("TencentCloud SDK return nil response, %s", request.GetAction())
8383
}
84-
if len(response.Response.DBInstanceIdSet) == 0 {
85-
errRet = errors.New("TencentCloud SDK returns empty postgresql instance ID")
86-
} else if len(response.Response.DBInstanceIdSet) > 1 {
87-
errRet = errors.New("TencentCloud SDK returns more than one postgresql instance ID")
88-
}
8984

9085
return
9186
}

0 commit comments

Comments
 (0)