@@ -262,12 +262,12 @@ func resourceTencentCloudCynosdbClusterCreate(d *schema.ResourceData, meta inter
262
262
return err
263
263
}
264
264
var rwGroupId string
265
- var roGroupId string
265
+ var roGroupIds [] string
266
266
for _ , insGrp := range insGrps .Response .InstanceGrpInfoList {
267
267
if * insGrp .Type == CYNOSDB_INSGRP_HA {
268
268
rwGroupId = * insGrp .InstanceGrpId
269
269
} else if * insGrp .Type == CYNOSDB_INSGRP_RO {
270
- roGroupId = * insGrp .InstanceGrpId
270
+ roGroupIds = append ( roGroupIds , * insGrp .InstanceGrpId )
271
271
}
272
272
}
273
273
if v , ok := d .GetOk ("rw_group_sg" ); ok {
@@ -280,14 +280,16 @@ func resourceTencentCloudCynosdbClusterCreate(d *schema.ResourceData, meta inter
280
280
return err
281
281
}
282
282
}
283
- if v , ok := d .GetOk ("ro_group_sg" ); ok {
284
- vv := v .([]interface {})
285
- vvv := make ([]* string , 0 , len (vv ))
286
- for _ , item := range vv {
287
- vvv = append (vvv , helper .String (item .(string )))
288
- }
289
- if err = cynosdbService .ModifyInsGrpSecurityGroups (ctx , roGroupId , d .Get ("available_zone" ).(string ), vvv ); err != nil {
290
- return err
283
+ if v , ok := d .GetOk ("ro_group_sg" ); ok && len (roGroupIds ) > 0 {
284
+ for _ , roGroupId := range roGroupIds {
285
+ vv := v .([]interface {})
286
+ vvv := make ([]* string , 0 , len (vv ))
287
+ for _ , item := range vv {
288
+ vvv = append (vvv , helper .String (item .(string )))
289
+ }
290
+ if err = cynosdbService .ModifyInsGrpSecurityGroups (ctx , roGroupId , d .Get ("available_zone" ).(string ), vvv ); err != nil {
291
+ return err
292
+ }
291
293
}
292
294
}
293
295
@@ -596,18 +598,19 @@ func resourceTencentCloudCynosdbClusterUpdate(d *schema.ResourceData, meta inter
596
598
if err := cynosdbService .ModifyInsGrpSecurityGroups (ctx , d .Get ("rw_group_id" ).(string ), d .Get ("available_zone" ).(string ), vv ); err != nil {
597
599
return err
598
600
}
599
- d .SetPartial ("rw_group_sg" )
600
601
}
601
602
if d .HasChange ("ro_group_sg" ) {
602
603
v := d .Get ("ro_group_sg" ).([]interface {})
603
604
vv := make ([]* string , 0 , len (v ))
604
605
for _ , item := range v {
605
606
vv = append (vv , helper .String (item .(string )))
606
607
}
607
- if err := cynosdbService .ModifyInsGrpSecurityGroups (ctx , d .Get ("ro_group_id" ).(string ), d .Get ("available_zone" ).(string ), vv ); err != nil {
608
- return err
608
+ if roGroupId := d .Get ("ro_group_id" ).(string ); roGroupId != "" {
609
+ err := cynosdbService .ModifyInsGrpSecurityGroups (ctx , roGroupId , d .Get ("available_zone" ).(string ), vv )
610
+ if err != nil {
611
+ return err
612
+ }
609
613
}
610
- d .SetPartial ("ro_group_sg" )
611
614
}
612
615
613
616
d .Partial (false )
0 commit comments