Skip to content

Commit 66f4311

Browse files
authored
fix(eni): [126301231] tencentcloud_eni optmize code logic, add orderly_security_groups (#3464)
* add * add * add * add * add * add * add
1 parent 60be647 commit 66f4311

File tree

4 files changed

+40
-12
lines changed

4 files changed

+40
-12
lines changed

.changelog/3464.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_eni: optmize code logic, add `orderly_security_groups`
3+
```

tencentcloud/services/vpc/resource_tc_eni.go

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,22 @@ func ResourceTencentCloudEni() *schema.Resource {
7474
Description: "Description of the ENI, maximum length 60.",
7575
},
7676
"security_groups": {
77-
Type: schema.TypeSet,
78-
Optional: true,
79-
Computed: true,
80-
Elem: &schema.Schema{Type: schema.TypeString},
81-
Set: schema.HashString,
82-
Description: "A set of security group IDs.",
77+
Type: schema.TypeSet,
78+
Optional: true,
79+
Computed: true,
80+
Elem: &schema.Schema{Type: schema.TypeString},
81+
Set: schema.HashString,
82+
ConflictsWith: []string{"orderly_security_groups"},
83+
Deprecated: "It has been deprecated from version 1.82.15. Use `orderly_security_groups` instead.",
84+
Description: "A set of security group IDs.",
85+
},
86+
"orderly_security_groups": {
87+
Type: schema.TypeList,
88+
Optional: true,
89+
Computed: true,
90+
ConflictsWith: []string{"security_groups"},
91+
Elem: &schema.Schema{Type: schema.TypeString},
92+
Description: "List of security group IDs.",
8393
},
8494
"ipv4s": {
8595
Type: schema.TypeSet,
@@ -179,6 +189,10 @@ func resourceTencentCloudEniCreate(d *schema.ResourceData, m interface{}) error
179189
securityGroups = helper.InterfacesStrings(raw.(*schema.Set).List())
180190
}
181191

192+
if raw, ok := d.GetOk("orderly_security_groups"); ok {
193+
securityGroups = helper.InterfacesStrings(raw.([]interface{}))
194+
}
195+
182196
if raw, ok := d.GetOk("ipv4s"); ok {
183197
set := raw.(*schema.Set)
184198
ipv4s = make([]VpcEniIP, 0, set.Len())
@@ -359,6 +373,7 @@ func resourceTencentCloudEniRead(d *schema.ResourceData, m interface{}) error {
359373
sgs = append(sgs, *sg)
360374
}
361375
_ = d.Set("security_groups", sgs)
376+
_ = d.Set("orderly_security_groups", sgs)
362377

363378
ipv4s := make([]map[string]interface{}, 0, len(eni.PrivateIpAddressSet))
364379
for _, ipv4 := range eni.PrivateIpAddressSet {
@@ -423,8 +438,17 @@ func resourceTencentCloudEniUpdate(d *schema.ResourceData, m interface{}) error
423438

424439
if d.HasChange("security_groups") {
425440
updateAttrs = append(updateAttrs, "security_groups")
441+
if v, ok := d.GetOk("security_groups"); ok {
442+
sgs = helper.InterfacesStrings(v.(*schema.Set).List())
443+
}
444+
}
445+
446+
if d.HasChange("orderly_security_groups") {
447+
updateAttrs = append(updateAttrs, "orderly_security_groups")
448+
if v, ok := d.GetOk("orderly_security_groups"); ok {
449+
sgs = helper.InterfacesStrings(v.([]interface{}))
450+
}
426451
}
427-
sgs = helper.InterfacesStrings(d.Get("security_groups").(*schema.Set).List())
428452

429453
if len(updateAttrs) > 0 {
430454
if err := vpcService.ModifyEniAttribute(ctx, id, name, desc, sgs); err != nil {

tencentcloud/services/vpc/resource_tc_eni.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ resource "tencentcloud_eni" "example" {
4646
subnet_id = tencentcloud_subnet.subnet.id
4747
description = "eni desc."
4848
ipv4_count = 1
49-
security_groups = [
49+
orderly_security_groups = [
5050
tencentcloud_security_group.example1.id,
5151
tencentcloud_security_group.example2.id
5252
]
@@ -58,5 +58,5 @@ Import
5858
ENI can be imported using the id, e.g.
5959

6060
```
61-
$ terraform import tencentcloud_eni.foo eni-qka182br
61+
$ terraform import tencentcloud_eni.example eni-qka182br
6262
```

website/docs/r/eni.html.markdown

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ resource "tencentcloud_eni" "example" {
5757
subnet_id = tencentcloud_subnet.subnet.id
5858
description = "eni desc."
5959
ipv4_count = 1
60-
security_groups = [
60+
orderly_security_groups = [
6161
tencentcloud_security_group.example1.id,
6262
tencentcloud_security_group.example2.id
6363
]
@@ -74,7 +74,8 @@ The following arguments are supported:
7474
* `description` - (Optional, String) Description of the ENI, maximum length 60.
7575
* `ipv4_count` - (Optional, Int) The number of intranet IPv4s. When it is greater than 1, there is only one primary intranet IP. The others are auxiliary intranet IPs, which conflict with `ipv4s`.
7676
* `ipv4s` - (Optional, Set) Applying for intranet IPv4s collection, conflict with `ipv4_count`. When there are multiple ipv4s, can only be one primary IP, and the maximum length of the array is 30. Each element contains the following attributes:
77-
* `security_groups` - (Optional, Set: [`String`]) A set of security group IDs.
77+
* `orderly_security_groups` - (Optional, List: [`String`]) List of security group IDs.
78+
* `security_groups` - (Optional, Set: [`String`], **Deprecated**) It has been deprecated from version 1.82.15. Use `orderly_security_groups` instead. A set of security group IDs.
7879
* `tags` - (Optional, Map) Tags of the ENI.
7980

8081
The `ipv4s` object supports the following:
@@ -104,6 +105,6 @@ In addition to all arguments above, the following attributes are exported:
104105
ENI can be imported using the id, e.g.
105106

106107
```
107-
$ terraform import tencentcloud_eni.foo eni-qka182br
108+
$ terraform import tencentcloud_eni.example eni-qka182br
108109
```
109110

0 commit comments

Comments
 (0)