Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cf9f931

Browse files
authoredApr 22, 2024
feat(postgresql): [117103987]support vip for pg ro group. (#2595)
* feat(postgresql): [117103987]support vip for pg ro group. * 1.e2e passed. 2.add docs * delete the useless pg html.md
1 parent f5881ef commit cf9f931

7 files changed

+101
-186
lines changed
 

‎.changelog/2595.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_postgresql_readonly_group: Support the computed param `ip` of the `net_info_list`
3+
```

‎tencentcloud/services/postgresql/resource_tc_postgresql_readonly_group.go

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,25 @@ func ResourceTencentCloudPostgresqlReadonlyGroup() *schema.Resource {
5252
Required: true,
5353
Description: "VPC subnet ID.",
5454
},
55+
"net_info_list": {
56+
Type: schema.TypeList,
57+
Computed: true,
58+
Description: "List of db instance net info.",
59+
Elem: &schema.Resource{
60+
Schema: map[string]*schema.Schema{
61+
"ip": {
62+
Type: schema.TypeString,
63+
Computed: true,
64+
Description: "Ip address of the net info.",
65+
},
66+
"port": {
67+
Type: schema.TypeInt,
68+
Computed: true,
69+
Description: "Port of the net info.",
70+
},
71+
},
72+
},
73+
},
5574
"replay_lag_eliminate": {
5675
Type: schema.TypeInt,
5776
Required: true,
@@ -191,8 +210,7 @@ func resourceTencentCloudPostgresqlReadOnlyGroupCreate(d *schema.ResourceData, m
191210
return err
192211
}
193212

194-
//return resourceTencentCloudPostgresqlReadOnlyGroupRead(d, meta)
195-
return nil
213+
return resourceTencentCloudPostgresqlReadOnlyGroupRead(d, meta)
196214
}
197215

198216
func resourceTencentCloudPostgresqlReadOnlyGroupRead(d *schema.ResourceData, meta interface{}) error {
@@ -202,17 +220,34 @@ func resourceTencentCloudPostgresqlReadOnlyGroupRead(d *schema.ResourceData, met
202220
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
203221

204222
// for now, the id should be the master db instance id, cause the describe api only support this kind of filter.
205-
var id string
223+
var masterInsId string
206224
if v, ok := d.GetOk("master_db_instance_id"); ok {
207-
id = v.(string)
225+
masterInsId = v.(string)
208226
}
227+
roGroupId := d.Id()
209228

210229
postgresqlService := PostgresqlService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
211-
_, err := postgresqlService.DescribePostgresqlReadOnlyGroupById(ctx, id)
230+
netInfos, err := postgresqlService.DescribePostgresqlReadonlyGroupNetInfosById(ctx, masterInsId, roGroupId)
212231
if err != nil {
213232
return err
214233
}
215234

235+
if netInfos != nil {
236+
netInfoList := []interface{}{}
237+
for _, netInfo := range netInfos {
238+
netInfoMap := map[string]interface{}{}
239+
240+
if netInfo.Ip != nil {
241+
netInfoMap["ip"] = *netInfo.Ip
242+
}
243+
if netInfo.Port != nil {
244+
netInfoMap["port"] = helper.UInt64Int64(*netInfo.Port)
245+
}
246+
netInfoList = append(netInfoList, netInfoMap)
247+
}
248+
_ = d.Set("net_info_list", netInfoList)
249+
}
250+
216251
return nil
217252
}
218253

@@ -362,7 +397,7 @@ func resourceTencentCloudPostgresqlReadOnlyGroupUpdate(d *schema.ResourceData, m
362397
if err != nil {
363398
return err
364399
}
365-
return nil
400+
return resourceTencentCloudPostgresqlReadOnlyGroupRead(d, meta)
366401
}
367402

368403
func resourceTencentCLoudPostgresqlReadOnlyGroupDelete(d *schema.ResourceData, meta interface{}) error {

‎tencentcloud/services/postgresql/resource_tc_postgresql_readonly_group_test.go

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ func TestAccTencentCloudPostgresqlReadonlyGroupResource_basic(t *testing.T) {
3737
resource.TestCheckResourceAttr(testPostgresqlReadonlyGroupResourceKey, "max_replay_lag", "100"),
3838
resource.TestCheckResourceAttr(testPostgresqlReadonlyGroupResourceKey, "max_replay_latency", "512"),
3939
resource.TestCheckResourceAttr(testPostgresqlReadonlyGroupResourceKey, "min_delay_eliminate_reserve", "1"),
40+
resource.TestCheckResourceAttr(testPostgresqlReadonlyGroupResourceKey, "min_delay_eliminate_reserve", "1"),
41+
resource.TestCheckResourceAttrSet(testPostgresqlReadonlyGroupResourceKey, "net_info_list.#"),
42+
resource.TestCheckResourceAttrSet(testPostgresqlReadonlyGroupResourceKey, "net_info_list.0.ip"),
43+
resource.TestCheckResourceAttr(testPostgresqlReadonlyGroupResourceKey, "net_info_list.0.port", "5432"),
4044
),
4145
},
4246
{
@@ -51,15 +55,37 @@ func TestAccTencentCloudPostgresqlReadonlyGroupResource_basic(t *testing.T) {
5155
resource.TestCheckResourceAttr(testPostgresqlReadonlyGroupResourceKey, "name", "tf_ro_group_test_updated"),
5256
resource.TestCheckResourceAttrSet(testPostgresqlReadonlyGroupResourceKey, "vpc_id"),
5357
resource.TestCheckResourceAttrSet(testPostgresqlReadonlyGroupResourceKey, "subnet_id"),
58+
resource.TestCheckResourceAttrSet(testPostgresqlReadonlyGroupResourceKey, "net_info_list.#"),
59+
resource.TestCheckResourceAttrSet(testPostgresqlReadonlyGroupResourceKey, "net_info_list.0.ip"),
60+
resource.TestCheckResourceAttr(testPostgresqlReadonlyGroupResourceKey, "net_info_list.0.port", "5432"),
5461
),
5562
},
5663
},
5764
})
5865
}
5966

60-
const testAccPostgresqlReadonlyGroupInstance string = tcacctest.CommonPresetPGSQL + tcacctest.DefaultVpcSubnets + `
67+
const testAccPostgresqlReadonlyGroupInstance string = tcacctest.DefaultVpcSubnets + `
68+
resource "tencentcloud_postgresql_instance" "test" {
69+
name = "example"
70+
availability_zone = var.default_az
71+
charge_type = "POSTPAID_BY_HOUR"
72+
vpc_id = local.vpc_id
73+
subnet_id = local.subnet_id
74+
engine_version = "10.4"
75+
root_user = "root123"
76+
root_password = "Root123$"
77+
charset = "UTF8"
78+
project_id = 0
79+
memory = 2
80+
storage = 10
81+
82+
tags = {
83+
test = "tf"
84+
}
85+
}
86+
6187
resource "tencentcloud_postgresql_readonly_group" "group" {
62-
master_db_instance_id = local.pgsql_id
88+
master_db_instance_id = tencentcloud_postgresql_instance.test.id
6389
name = "tf_ro_group_test"
6490
project_id = 0
6591
vpc_id = local.vpc_id
@@ -72,8 +98,27 @@ resource "tencentcloud_postgresql_readonly_group" "group" {
7298
}
7399
`
74100

75-
const testAccPostgresqlReadonlyGroupInstance_update string = tcacctest.CommonPresetPGSQL + tcacctest.DefaultVpcSubnets + `
76-
resource "tencentcloud_vpc" "vpc" {
101+
const testAccPostgresqlReadonlyGroupInstance_update string = tcacctest.DefaultVpcSubnets + `
102+
resource "tencentcloud_postgresql_instance" "test" {
103+
name = "example"
104+
availability_zone = var.default_az
105+
charge_type = "POSTPAID_BY_HOUR"
106+
vpc_id = local.vpc_id
107+
subnet_id = local.subnet_id
108+
engine_version = "10.4"
109+
root_user = "root123"
110+
root_password = "Root123$"
111+
charset = "UTF8"
112+
project_id = 0
113+
memory = 2
114+
storage = 10
115+
116+
tags = {
117+
test = "tf"
118+
}
119+
}
120+
121+
resource "tencentcloud_vpc" "vpc" {
77122
cidr_block = "172.18.111.0/24"
78123
name = "test-pg-rogroup-network-vpc"
79124
}
@@ -91,7 +136,7 @@ resource "tencentcloud_vpc" "vpc" {
91136
}
92137
93138
resource "tencentcloud_postgresql_readonly_group" "group" {
94-
master_db_instance_id = local.pgsql_id
139+
master_db_instance_id = tencentcloud_postgresql_instance.test.id
95140
name = "tf_ro_group_test_updated"
96141
project_id = 0
97142
vpc_id = local.new_vpc_id

‎tencentcloud/services/postgresql/service_tencentcloud_postgresql.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,10 @@ func (me *PostgresqlService) DescribePostgresqlReadonlyGroupNetInfosById(ctx con
13091309
Name: helper.String("db-master-instance-id"),
13101310
Values: []*string{helper.String(dbInstanceId)},
13111311
},
1312+
{
1313+
Name: helper.String("read-only-group-id"),
1314+
Values: []*string{helper.String(roGroupId)},
1315+
},
13121316
},
13131317
}
13141318

‎website/docs/r/postgresql_instance_network_access_attachment.html.markdown

Lines changed: 0 additions & 71 deletions
This file was deleted.

‎website/docs/r/postgresql_readonly_group.html.markdown

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,8 @@ In addition to all arguments above, the following attributes are exported:
5151

5252
* `id` - ID of the resource.
5353
* `create_time` - Create time of the postgresql instance.
54+
* `net_info_list` - List of db instance net info.
55+
* `ip` - Ip address of the net info.
56+
* `port` - Port of the net info.
5457

5558

‎website/docs/r/postgresql_readonly_group_network_access_attachment.html.markdown

Lines changed: 0 additions & 104 deletions
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.