Skip to content

Commit be0a468

Browse files
committed
feat(postgresql): [117103987]support vip for pg ro group.
1 parent f5881ef commit be0a468

File tree

2 files changed

+45
-6
lines changed

2 files changed

+45
-6
lines changed

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_infos": {
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.TypeString,
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"] = netInfo.Port
245+
}
246+
netInfoList = append(netInfoList, netInfoMap)
247+
}
248+
_ = d.Set("net_infos", 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/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

0 commit comments

Comments
 (0)