Skip to content

Commit a859da7

Browse files
authored
fix(clb): [124504125] tencentcloud_clb_instance optmize security_groups nil value (#3415)
* add * add
1 parent c2d4079 commit a859da7

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

.changelog/3415.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_clb_instance: optmize `security_groups` nil value
3+
```

tencentcloud/services/clb/resource_tc_clb_instance.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,9 @@ func resourceTencentCloudClbInstanceCreate(d *schema.ResourceData, meta interfac
338338
if v, ok := d.Get("snat_ips").([]interface{}); ok && len(v) > 0 {
339339
for i := range v {
340340
item := v[i].(map[string]interface{})
341-
subnetId := item["subnet_id"].(string)
342-
snatIp := &clb.SnatIp{
343-
SubnetId: &subnetId,
341+
snatIp := &clb.SnatIp{}
342+
if v, ok := item["subnet_id"].(string); ok && v != "" {
343+
snatIp.SubnetId = &v
344344
}
345345

346346
if v, ok := item["ip"].(string); ok && v != "" {
@@ -470,8 +470,9 @@ func resourceTencentCloudClbInstanceCreate(d *schema.ResourceData, meta interfac
470470
sgRequest.SecurityGroups = make([]*string, 0, len(securityGroups))
471471
for i := range securityGroups {
472472
if securityGroups[i] != nil {
473-
securityGroup := securityGroups[i].(string)
474-
sgRequest.SecurityGroups = append(sgRequest.SecurityGroups, &securityGroup)
473+
if securityGroup, ok := securityGroups[i].(string); ok && securityGroup != "" {
474+
sgRequest.SecurityGroups = append(sgRequest.SecurityGroups, &securityGroup)
475+
}
475476
}
476477
}
477478

@@ -891,8 +892,9 @@ func resourceTencentCloudClbInstanceUpdate(d *schema.ResourceData, meta interfac
891892
securityGroups := d.Get("security_groups").([]interface{})
892893
sgRequest.SecurityGroups = make([]*string, 0, len(securityGroups))
893894
for i := range securityGroups {
894-
securityGroup := securityGroups[i].(string)
895-
sgRequest.SecurityGroups = append(sgRequest.SecurityGroups, &securityGroup)
895+
if securityGroup, ok := securityGroups[i].(string); ok && securityGroup != "" {
896+
sgRequest.SecurityGroups = append(sgRequest.SecurityGroups, &securityGroup)
897+
}
896898
}
897899

898900
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {

0 commit comments

Comments
 (0)