Skip to content

Commit f9c7ca6

Browse files
committed
fix error
1 parent 08c7d0e commit f9c7ca6

4 files changed

+169
-68
lines changed

tencentcloud/services/postgresql/resource_tc_postgresql_instance.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ func resourceTencentCloudPostgresqlInstanceCreate(d *schema.ResourceData, meta i
346346

347347
var instanceId, specVersion, specCode string
348348
var outErr, inErr error
349-
var allowVersion, allowMemory []string
349+
var allowVersion, allowSpec []string
350350

351351
var (
352352
dbMajorVersion = ""
@@ -416,19 +416,17 @@ func resourceTencentCloudPostgresqlInstanceCreate(d *schema.ResourceData, meta i
416416
}
417417
if *info.Version == dbVersion {
418418
specVersion = *info.Version
419-
memoryString := fmt.Sprintf("%d", int(*info.Memory)/1024)
420-
if !tccommon.IsContains(allowMemory, memoryString) {
421-
allowMemory = append(allowMemory, memoryString)
419+
specString := fmt.Sprintf("(%d, %d)", int(*info.Memory)/1024, int(*info.Cpu))
420+
if !tccommon.IsContains(allowSpec, specString) {
421+
allowSpec = append(allowSpec, specString)
422422
}
423423

424-
if cpu != 0 {
425-
if int(*info.Cpu) == cpu && int(*info.Memory)/1024 == memory {
426-
specCode = *info.SpecCode
427-
break
428-
}
424+
if cpu != 0 && int(*info.Cpu) == cpu && int(*info.Memory)/1024 == memory {
425+
specCode = *info.SpecCode
426+
break
429427
}
430428

431-
if int(*info.Memory)/1024 == memory {
429+
if cpu == 0 && int(*info.Memory)/1024 == memory {
432430
specCode = *info.SpecCode
433431
break
434432
}
@@ -445,7 +443,8 @@ func resourceTencentCloudPostgresqlInstanceCreate(d *schema.ResourceData, meta i
445443
}
446444

447445
if specCode == "" {
448-
return fmt.Errorf(`The "memory" value: %d is invalid, Valid values are one of: %s`, memory, strings.Join(allowMemory, `, `))
446+
return fmt.Errorf(`The "memory" value: %d or the "cpu" value: %d is invalid, Valid combine values are one of: %s .`,
447+
memory, cpu, strings.Join(allowSpec, `; `))
449448
}
450449

451450
var dbNodeSet []*postgresql.DBNode

tencentcloud/services/postgresql/resource_tc_postgresql_readonly_instance.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ func resourceTencentCloudPostgresqlReadOnlyInstanceCreate(d *schema.ResourceData
248248
//}
249249

250250
// get specCode with db_version and memory
251-
var allowVersion, allowMemory []string
251+
var allowVersion, allowSpec []string
252252
var specVersion, specCode string
253253
err := resource.Retry(tccommon.ReadRetryTimeout*5, func() *resource.RetryError {
254254
speccodes, inErr := postgresqlService.DescribeSpecinfos(ctx, zone)
@@ -259,21 +259,20 @@ func resourceTencentCloudPostgresqlReadOnlyInstanceCreate(d *schema.ResourceData
259259
if !tccommon.IsContains(allowVersion, *info.Version) {
260260
allowVersion = append(allowVersion, *info.Version)
261261
}
262+
262263
if *info.Version == dbVersion {
263264
specVersion = *info.Version
264-
memoryString := fmt.Sprintf("%d", int(*info.Memory)/1024)
265-
if !tccommon.IsContains(allowMemory, memoryString) {
266-
allowMemory = append(allowMemory, memoryString)
265+
specString := fmt.Sprintf("(%d, %d)", int(*info.Memory)/1024, int(*info.Cpu))
266+
if !tccommon.IsContains(allowSpec, specString) {
267+
allowSpec = append(allowSpec, specString)
267268
}
268269

269-
if cpu != 0 {
270-
if int(*info.Cpu) == cpu && int(*info.Memory)/1024 == memory {
271-
specCode = *info.SpecCode
272-
break
273-
}
270+
if cpu != 0 && int(*info.Cpu) == cpu && int(*info.Memory)/1024 == memory {
271+
specCode = *info.SpecCode
272+
break
274273
}
275274

276-
if int(*info.Memory)/1024 == memory {
275+
if cpu == 0 && int(*info.Memory)/1024 == memory {
277276
specCode = *info.SpecCode
278277
break
279278
}
@@ -288,7 +287,8 @@ func resourceTencentCloudPostgresqlReadOnlyInstanceCreate(d *schema.ResourceData
288287
return fmt.Errorf(`The "db_version" value: "%s" is invalid, Valid values are one of: "%s"`, dbVersion, strings.Join(allowVersion, `", "`))
289288
}
290289
if specCode == "" {
291-
return fmt.Errorf(`The "storage" value: %d is invalid, Valid values are one of: %s`, memory, strings.Join(allowMemory, `, `))
290+
return fmt.Errorf(`The "memory" value: %d or the "cpu" value: %d is invalid, Valid combine values are one of: %s .`,
291+
memory, cpu, strings.Join(allowSpec, `; `))
292292
}
293293
request.SpecCode = helper.String(specCode)
294294

tencentcloud/services/postgresql/resource_tc_postgresql_readonly_instance.md

Lines changed: 74 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,88 @@ Use this resource to create postgresql readonly instance.
33
Example Usage
44

55
```hcl
6-
resource "tencentcloud_postgresql_readonly_instance" "readonly" {
7-
availability_zone = "ap-guangzhou-3"
6+
variable "availability_zone" {
7+
default = "ap-guangzhou-3"
8+
}
9+
10+
# create vpc
11+
resource "tencentcloud_vpc" "vpc" {
12+
name = "vpc"
13+
cidr_block = "10.0.0.0/16"
14+
}
15+
16+
# create vpc subnet
17+
resource "tencentcloud_subnet" "subnet" {
18+
availability_zone = var.availability_zone
19+
name = "subnet"
20+
vpc_id = tencentcloud_vpc.vpc.id
21+
cidr_block = "10.0.20.0/28"
22+
is_multicast = false
23+
}
24+
25+
# create postgresql
26+
resource "tencentcloud_postgresql_instance" "example" {
27+
name = "example"
28+
availability_zone = var.availability_zone
29+
charge_type = "POSTPAID_BY_HOUR"
30+
vpc_id = tencentcloud_vpc.vpc.id
31+
subnet_id = tencentcloud_subnet.subnet.id
32+
engine_version = "10.4"
33+
root_user = "root123"
34+
root_password = "Root123$"
35+
charset = "UTF8"
36+
project_id = 0
37+
memory = 2
38+
cpu = 1
39+
storage = 10
40+
41+
tags = {
42+
test = "tf"
43+
}
44+
}
45+
46+
resource "tencentcloud_postgresql_readonly_group" "example" {
47+
master_db_instance_id = tencentcloud_postgresql_instance.example.id
48+
name = "tf_ro_group"
49+
project_id = 0
50+
vpc_id = tencentcloud_vpc.vpc.id
51+
subnet_id = tencentcloud_subnet.subnet.id
52+
replay_lag_eliminate = 1
53+
replay_latency_eliminate = 1
54+
max_replay_lag = 100
55+
max_replay_latency = 512
56+
min_delay_eliminate_reserve = 1
57+
}
58+
59+
# create security group
60+
resource "tencentcloud_security_group" "example" {
61+
name = "tf-example"
62+
description = "sg desc."
63+
project_id = 0
64+
65+
tags = {
66+
"example" = "test"
67+
}
68+
}
69+
70+
resource "tencentcloud_postgresql_readonly_instance" "example" {
71+
read_only_group_id = tencentcloud_postgresql_readonly_group.example.id
72+
master_db_instance_id = tencentcloud_postgresql_instance.example.id
73+
zone = var.availability_zone
74+
name = "example"
875
auto_renew_flag = 0
976
db_version = "10.4"
1077
instance_charge_type = "POSTPAID_BY_HOUR"
11-
master_db_instance_id = local.pgsql_id
1278
memory = 4
1379
cpu = 2
14-
name = "hello"
80+
storage = 250
81+
vpc_id = tencentcloud_vpc.vpc.id
82+
subnet_id = tencentcloud_subnet.subnet.id
1583
need_support_ipv6 = 0
1684
project_id = 0
1785
security_groups_ids = [
18-
"sg-fefj5n6r",
86+
tencentcloud_security_group.example.id,
1987
]
20-
storage = 250
21-
subnet_id = local.subnet_id
22-
vpc_id = local.vpc_id
23-
read_only_group_id = tencentcloud_postgresql_readonly_group.new_ro_group.id
24-
}
25-
26-
resource "tencentcloud_postgresql_readonly_group" "new_ro_group" {
27-
master_db_instance_id = local.pgsql_id
28-
name = "tf_ro_group_test_new"
29-
project_id = 0
30-
vpc_id = local.vpc_id
31-
subnet_id = local.subnet_id
32-
replay_lag_eliminate = 1
33-
replay_latency_eliminate = 1
34-
max_replay_lag = 100
35-
max_replay_latency = 512
36-
min_delay_eliminate_reserve = 1
3788
}
3889
```
3990

@@ -42,5 +93,5 @@ Import
4293
postgresql readonly instance can be imported using the id, e.g.
4394

4495
```
45-
$ terraform import tencentcloud_postgresql_readonly_instance.readonly instance_id
96+
$ terraform import tencentcloud_postgresql_readonly_instance.example instance_id
4697
```

website/docs/r/postgresql_readonly_instance.html.markdown

Lines changed: 74 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,88 @@ Use this resource to create postgresql readonly instance.
1414
## Example Usage
1515

1616
```hcl
17-
resource "tencentcloud_postgresql_readonly_instance" "readonly" {
18-
availability_zone = "ap-guangzhou-3"
17+
variable "availability_zone" {
18+
default = "ap-guangzhou-3"
19+
}
20+
21+
# create vpc
22+
resource "tencentcloud_vpc" "vpc" {
23+
name = "vpc"
24+
cidr_block = "10.0.0.0/16"
25+
}
26+
27+
# create vpc subnet
28+
resource "tencentcloud_subnet" "subnet" {
29+
availability_zone = var.availability_zone
30+
name = "subnet"
31+
vpc_id = tencentcloud_vpc.vpc.id
32+
cidr_block = "10.0.20.0/28"
33+
is_multicast = false
34+
}
35+
36+
# create postgresql
37+
resource "tencentcloud_postgresql_instance" "example" {
38+
name = "example"
39+
availability_zone = var.availability_zone
40+
charge_type = "POSTPAID_BY_HOUR"
41+
vpc_id = tencentcloud_vpc.vpc.id
42+
subnet_id = tencentcloud_subnet.subnet.id
43+
engine_version = "10.4"
44+
root_user = "root123"
45+
root_password = "Root123$"
46+
charset = "UTF8"
47+
project_id = 0
48+
memory = 2
49+
cpu = 1
50+
storage = 10
51+
52+
tags = {
53+
test = "tf"
54+
}
55+
}
56+
57+
resource "tencentcloud_postgresql_readonly_group" "example" {
58+
master_db_instance_id = tencentcloud_postgresql_instance.example.id
59+
name = "tf_ro_group"
60+
project_id = 0
61+
vpc_id = tencentcloud_vpc.vpc.id
62+
subnet_id = tencentcloud_subnet.subnet.id
63+
replay_lag_eliminate = 1
64+
replay_latency_eliminate = 1
65+
max_replay_lag = 100
66+
max_replay_latency = 512
67+
min_delay_eliminate_reserve = 1
68+
}
69+
70+
# create security group
71+
resource "tencentcloud_security_group" "example" {
72+
name = "tf-example"
73+
description = "sg desc."
74+
project_id = 0
75+
76+
tags = {
77+
"example" = "test"
78+
}
79+
}
80+
81+
resource "tencentcloud_postgresql_readonly_instance" "example" {
82+
read_only_group_id = tencentcloud_postgresql_readonly_group.example.id
83+
master_db_instance_id = tencentcloud_postgresql_instance.example.id
84+
zone = var.availability_zone
85+
name = "example"
1986
auto_renew_flag = 0
2087
db_version = "10.4"
2188
instance_charge_type = "POSTPAID_BY_HOUR"
22-
master_db_instance_id = local.pgsql_id
2389
memory = 4
2490
cpu = 2
25-
name = "hello"
91+
storage = 250
92+
vpc_id = tencentcloud_vpc.vpc.id
93+
subnet_id = tencentcloud_subnet.subnet.id
2694
need_support_ipv6 = 0
2795
project_id = 0
2896
security_groups_ids = [
29-
"sg-fefj5n6r",
97+
tencentcloud_security_group.example.id,
3098
]
31-
storage = 250
32-
subnet_id = local.subnet_id
33-
vpc_id = local.vpc_id
34-
read_only_group_id = tencentcloud_postgresql_readonly_group.new_ro_group.id
35-
}
36-
37-
resource "tencentcloud_postgresql_readonly_group" "new_ro_group" {
38-
master_db_instance_id = local.pgsql_id
39-
name = "tf_ro_group_test_new"
40-
project_id = 0
41-
vpc_id = local.vpc_id
42-
subnet_id = local.subnet_id
43-
replay_lag_eliminate = 1
44-
replay_latency_eliminate = 1
45-
max_replay_lag = 100
46-
max_replay_latency = 512
47-
min_delay_eliminate_reserve = 1
4899
}
49100
```
50101

@@ -87,6 +138,6 @@ In addition to all arguments above, the following attributes are exported:
87138
postgresql readonly instance can be imported using the id, e.g.
88139

89140
```
90-
$ terraform import tencentcloud_postgresql_readonly_instance.readonly instance_id
141+
$ terraform import tencentcloud_postgresql_readonly_instance.example instance_id
91142
```
92143

0 commit comments

Comments
 (0)