Skip to content

Commit 5f6726a

Browse files
WeiMengXSWeiMengXS
andauthored
feat: set security_groups (#2285)
* feat: set `security_groups` * feat: set `security_groups` * feat: set `security_groups` * feat: set `security_groups` --------- Co-authored-by: WeiMengXS <nickcchen@tencent.com>
1 parent c032cb4 commit 5f6726a

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

.changelog/2285.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_mongodb_instance: support set `security_groups` state.
3+
```
4+
5+
```release-note:enhancement
6+
resource/tencentcloud_mongodb_sharding_instance: support set `security_groups` state.
7+
```
8+
9+

tencentcloud/resource_tc_mongodb_instance.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,17 @@ func resourceTencentCloudMongodbInstanceRead(d *schema.ResourceData, meta interf
372372
_ = d.Set("auto_renew_flag", *instance.AutoRenewFlag)
373373
}
374374

375+
groups, err := mongodbService.DescribeSecurityGroup(ctx, instanceId)
376+
if err != nil {
377+
return err
378+
}
379+
groupIds := make([]string, 0)
380+
for _, group := range groups {
381+
groupIds = append(groupIds, *group.SecurityGroupId)
382+
}
383+
if len(groupIds) > 1 {
384+
_ = d.Set("security_groups", groupIds)
385+
}
375386
switch *instance.MachineType {
376387
case MONGODB_MACHINE_TYPE_TGIO:
377388
_ = d.Set("machine_type", MONGODB_MACHINE_TYPE_HIO10G)

tencentcloud/resource_tc_mongodb_sharding_instance.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,9 @@ func resourceMongodbShardingInstanceRead(d *schema.ResourceData, meta interface{
404404
for _, group := range groups {
405405
groupIds = append(groupIds, *group.SecurityGroupId)
406406
}
407-
_ = d.Set("security_groups", groupIds)
408-
407+
if len(groupIds) > 1 {
408+
_ = d.Set("security_groups", groupIds)
409+
}
409410
replicateSets, err := mongodbService.DescribeDBInstanceNodeProperty(ctx, instanceId)
410411
if err != nil {
411412
return err

tencentcloud/resource_tc_mongodb_standby_instance.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,17 @@ func resourceTencentCloudMongodbStandbyInstanceRead(d *schema.ResourceData, meta
388388
_ = d.Set("auto_renew_flag", *instance.AutoRenewFlag)
389389
}
390390

391+
groups, err := mongodbService.DescribeSecurityGroup(ctx, instanceId)
392+
if err != nil {
393+
return err
394+
}
395+
groupIds := make([]string, 0)
396+
for _, group := range groups {
397+
groupIds = append(groupIds, *group.SecurityGroupId)
398+
}
399+
if len(groupIds) > 1 {
400+
_ = d.Set("security_groups", groupIds)
401+
}
391402
_ = d.Set("machine_type", *instance.MachineType)
392403
_ = d.Set("available_zone", instance.Zone)
393404
_ = d.Set("vpc_id", instance.VpcId)

0 commit comments

Comments
 (0)