Skip to content

Commit 46529fa

Browse files
authored
fix(vpc): [128000440] tencentcloud_vpc_acl update ingress and egress params (#3581)
* add * add
1 parent d380764 commit 46529fa

File tree

5 files changed

+82
-42
lines changed

5 files changed

+82
-42
lines changed

.changelog/3581.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_vpc_acl: update `ingress` and `egress` params
3+
```

tencentcloud/services/vpc/resource_tc_vpc_acl.go

Lines changed: 52 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ func ResourceTencentCloudVpcACL() *schema.Resource {
4343
Type: schema.TypeList,
4444
Optional: true,
4545
Elem: &schema.Schema{Type: schema.TypeString},
46-
Description: "Ingress rules. A rule must match the following format: [action]#[cidr_ip]#[port]#[protocol]. The available value of 'action' is `ACCEPT` and `DROP`. The 'cidr_ip' must be an IP address network or segment. The 'port' valid format is `80`, `80-90` or `ALL`. The available value of 'protocol' is `TCP`, `UDP`, `ICMP` and `ALL`. When 'protocol' is `ICMP` or `ALL`, the 'port' must be `ALL`.",
46+
Description: "Ingress rules. A rule must match the following format: [action]#[cidr_ip]#[port]#[protocol]#[description]. The available value of `action` is `ACCEPT` and `DROP`. The `cidr_ip` must be an IP address network or segment. The `port` valid format is `80`, `80-90` or `ALL`. The available value of 'protocol' is `TCP`, `UDP`, `ICMP` and `ALL`. When `protocol` is `ICMP` or `ALL`, the 'port' must be `ALL`. The `description` content must be in uppercase.",
4747
},
4848
"egress": {
4949
Type: schema.TypeList,
5050
Optional: true,
5151
Elem: &schema.Schema{Type: schema.TypeString},
52-
Description: "Egress rules. A rule must match the following format: [action]#[cidr_ip]#[port]#[protocol]. The available value of 'action' is `ACCEPT` and `DROP`. The 'cidr_ip' must be an IP address network or segment. The 'port' valid format is `80`, `80-90` or `ALL`. The available value of 'protocol' is `TCP`, `UDP`, `ICMP` and `ALL`. When 'protocol' is `ICMP` or `ALL`, the 'port' must be `ALL`.",
52+
Description: "Egress rules. A rule must match the following format: [action]#[cidr_ip]#[port]#[protocol]#[description]. The available value of `action` is `ACCEPT` and `DROP`. The `cidr_ip` must be an IP address network or segment. The `port` valid format is `80`, `80-90` or `ALL`. The available value of `protocol` is `TCP`, `UDP`, `ICMP` and `ALL`. When `protocol` is `ICMP` or `ALL`, the `port` must be `ALL`. The `description` content must be in uppercase.",
5353
},
5454
"tags": {
5555
Type: schema.TypeMap,
@@ -169,10 +169,11 @@ func resourceTencentCloudVpcACLRead(d *schema.ResourceData, meta interface{}) er
169169
}
170170

171171
var (
172-
action string
173-
cidrBlock string
174-
port string
175-
protocol string
172+
action string
173+
cidrBlock string
174+
port string
175+
protocol string
176+
description string
176177
)
177178

178179
if info.EgressEntries[i].Action != nil {
@@ -189,13 +190,27 @@ func resourceTencentCloudVpcACLRead(d *schema.ResourceData, meta interface{}) er
189190
if info.EgressEntries[i].Protocol != nil {
190191
protocol = *info.EgressEntries[i].Protocol
191192
}
193+
if info.EgressEntries[i].Description != nil {
194+
description = *info.EgressEntries[i].Description
195+
}
192196

193-
result := strings.Join([]string{
194-
action,
195-
cidrBlock,
196-
port,
197-
protocol,
198-
}, tccommon.FILED_SP)
197+
var result string
198+
if description != "" {
199+
result = strings.Join([]string{
200+
action,
201+
cidrBlock,
202+
port,
203+
protocol,
204+
description,
205+
}, tccommon.FILED_SP)
206+
} else {
207+
result = strings.Join([]string{
208+
action,
209+
cidrBlock,
210+
port,
211+
protocol,
212+
}, tccommon.FILED_SP)
213+
}
199214

200215
egressList = append(egressList, strings.ToUpper(result))
201216
}
@@ -208,10 +223,11 @@ func resourceTencentCloudVpcACLRead(d *schema.ResourceData, meta interface{}) er
208223
}
209224

210225
var (
211-
action string
212-
cidrBlock string
213-
port string
214-
protocol string
226+
action string
227+
cidrBlock string
228+
port string
229+
protocol string
230+
description string
215231
)
216232

217233
if info.IngressEntries[i].Action != nil {
@@ -228,13 +244,27 @@ func resourceTencentCloudVpcACLRead(d *schema.ResourceData, meta interface{}) er
228244
if info.IngressEntries[i].Protocol != nil {
229245
protocol = *info.IngressEntries[i].Protocol
230246
}
247+
if info.IngressEntries[i].Description != nil {
248+
description = *info.IngressEntries[i].Description
249+
}
231250

232-
result := strings.Join([]string{
233-
action,
234-
cidrBlock,
235-
port,
236-
protocol,
237-
}, tccommon.FILED_SP)
251+
var result string
252+
if description != "" {
253+
result = strings.Join([]string{
254+
action,
255+
cidrBlock,
256+
port,
257+
protocol,
258+
description,
259+
}, tccommon.FILED_SP)
260+
} else {
261+
result = strings.Join([]string{
262+
action,
263+
cidrBlock,
264+
port,
265+
protocol,
266+
}, tccommon.FILED_SP)
267+
}
238268
ingressList = append(ingressList, strings.ToUpper(result))
239269
}
240270
_ = d.Set("egress", egressList)

tencentcloud/services/vpc/resource_tc_vpc_acl.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ resource "tencentcloud_vpc" "vpc" {
99
}
1010
1111
resource "tencentcloud_vpc_acl" "example" {
12-
vpc_id = tencentcloud_vpc.vpc.id
13-
name = "tf-example"
12+
vpc_id = tencentcloud_vpc.vpc.id
13+
name = "tf-example"
1414
ingress = [
1515
"ACCEPT#192.168.1.0/24#800#TCP",
16-
"ACCEPT#192.168.1.0/24#800-900#TCP",
16+
"ACCEPT#192.168.1.0/24#800-900#TCP#DESCRIPTION",
1717
]
1818
egress = [
1919
"ACCEPT#192.168.1.0/24#800#TCP",
20-
"ACCEPT#192.168.1.0/24#800-900#TCP",
20+
"ACCEPT#192.168.1.0/24#800-900#TCP#DESCRIPTION",
2121
]
2222
}
2323
```

tencentcloud/services/vpc/service_tencentcloud_vpc.go

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,11 @@ var portRE = regexp.MustCompile(`^(\d{1,5},)*\d{1,5}$|^\d{1,5}-\d{1,5}$`)
163163

164164
// acl rule
165165
type VpcACLRule struct {
166-
action string
167-
cidrIp string
168-
port string
169-
protocol string
166+
action string
167+
cidrIp string
168+
port string
169+
protocol string
170+
description string
170171
}
171172

172173
type VpcEniIP struct {
@@ -3798,12 +3799,16 @@ func waitEniDetach(ctx context.Context, id string, client *vpc.Client) error {
37983799
// deal acl
37993800
func parseACLRule(str string) (liteRule VpcACLRule, err error) {
38003801
split := strings.Split(str, "#")
3801-
if len(split) != 4 {
3802+
if !(len(split) == 4 || len(split) == 5) {
38023803
err = fmt.Errorf("invalid acl rule %s", str)
38033804
return
38043805
}
38053806

3806-
liteRule.action, liteRule.cidrIp, liteRule.port, liteRule.protocol = split[0], split[1], split[2], split[3]
3807+
if len(split) == 4 {
3808+
liteRule.action, liteRule.cidrIp, liteRule.port, liteRule.protocol = split[0], split[1], split[2], split[3]
3809+
} else {
3810+
liteRule.action, liteRule.cidrIp, liteRule.port, liteRule.protocol, liteRule.description = split[0], split[1], split[2], split[3], split[4]
3811+
}
38073812

38083813
switch liteRule.action {
38093814
default:
@@ -3908,9 +3913,10 @@ func (me *VpcService) ModifyNetWorkAclRules(ctx context.Context, aclID string, i
39083913

39093914
for i := range ingressParm {
39103915
policy := &vpc.NetworkAclEntry{
3911-
Protocol: &ingressParm[i].protocol,
3912-
CidrBlock: &ingressParm[i].cidrIp,
3913-
Action: &ingressParm[i].action,
3916+
Protocol: &ingressParm[i].protocol,
3917+
CidrBlock: &ingressParm[i].cidrIp,
3918+
Action: &ingressParm[i].action,
3919+
Description: &ingressParm[i].description,
39143920
}
39153921

39163922
if ingressParm[i].port != "" {
@@ -3922,9 +3928,10 @@ func (me *VpcService) ModifyNetWorkAclRules(ctx context.Context, aclID string, i
39223928

39233929
for i := range egressParm {
39243930
policy := &vpc.NetworkAclEntry{
3925-
Protocol: &egressParm[i].protocol,
3926-
CidrBlock: &egressParm[i].cidrIp,
3927-
Action: &egressParm[i].action,
3931+
Protocol: &egressParm[i].protocol,
3932+
CidrBlock: &egressParm[i].cidrIp,
3933+
Action: &egressParm[i].action,
3934+
Description: &egressParm[i].description,
39283935
}
39293936

39303937
if egressParm[i].port != "" {

website/docs/r/vpc_acl.html.markdown

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ resource "tencentcloud_vpc_acl" "example" {
2424
name = "tf-example"
2525
ingress = [
2626
"ACCEPT#192.168.1.0/24#800#TCP",
27-
"ACCEPT#192.168.1.0/24#800-900#TCP",
27+
"ACCEPT#192.168.1.0/24#800-900#TCP#DESCRIPTION",
2828
]
2929
egress = [
3030
"ACCEPT#192.168.1.0/24#800#TCP",
31-
"ACCEPT#192.168.1.0/24#800-900#TCP",
31+
"ACCEPT#192.168.1.0/24#800-900#TCP#DESCRIPTION",
3232
]
3333
}
3434
```
@@ -39,8 +39,8 @@ The following arguments are supported:
3939

4040
* `name` - (Required, String) Name of the network ACL.
4141
* `vpc_id` - (Required, String) ID of the VPC instance.
42-
* `egress` - (Optional, List: [`String`]) Egress rules. A rule must match the following format: [action]#[cidr_ip]#[port]#[protocol]. The available value of 'action' is `ACCEPT` and `DROP`. The 'cidr_ip' must be an IP address network or segment. The 'port' valid format is `80`, `80-90` or `ALL`. The available value of 'protocol' is `TCP`, `UDP`, `ICMP` and `ALL`. When 'protocol' is `ICMP` or `ALL`, the 'port' must be `ALL`.
43-
* `ingress` - (Optional, List: [`String`]) Ingress rules. A rule must match the following format: [action]#[cidr_ip]#[port]#[protocol]. The available value of 'action' is `ACCEPT` and `DROP`. The 'cidr_ip' must be an IP address network or segment. The 'port' valid format is `80`, `80-90` or `ALL`. The available value of 'protocol' is `TCP`, `UDP`, `ICMP` and `ALL`. When 'protocol' is `ICMP` or `ALL`, the 'port' must be `ALL`.
42+
* `egress` - (Optional, List: [`String`]) Egress rules. A rule must match the following format: [action]#[cidr_ip]#[port]#[protocol]#[description]. The available value of `action` is `ACCEPT` and `DROP`. The `cidr_ip` must be an IP address network or segment. The `port` valid format is `80`, `80-90` or `ALL`. The available value of `protocol` is `TCP`, `UDP`, `ICMP` and `ALL`. When `protocol` is `ICMP` or `ALL`, the `port` must be `ALL`. The `description` content must be in uppercase.
43+
* `ingress` - (Optional, List: [`String`]) Ingress rules. A rule must match the following format: [action]#[cidr_ip]#[port]#[protocol]#[description]. The available value of `action` is `ACCEPT` and `DROP`. The `cidr_ip` must be an IP address network or segment. The `port` valid format is `80`, `80-90` or `ALL`. The available value of 'protocol' is `TCP`, `UDP`, `ICMP` and `ALL`. When `protocol` is `ICMP` or `ALL`, the 'port' must be `ALL`. The `description` content must be in uppercase.
4444
* `tags` - (Optional, Map) Tags of the vpc acl.
4545

4646
## Attributes Reference

0 commit comments

Comments
 (0)