Skip to content

Commit b917173

Browse files
committed
remove unused coding and logic;modify field
1 parent 20f2aba commit b917173

9 files changed

+50
-46
lines changed

examples/tencentcloud-vpc/main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ data "tencentcloud_vpc_instances" "tags_instances" {
1414

1515
data "tencentcloud_vpc_instances" "default" {}
1616

17-
resource "tencentcloud_vpc_acl" "foo" {
17+
resource "tencentcloud_vpc_acl" "default" {
1818
vpc_id = data.tencentcloud_vpc_instances.default.instance_list.0.vpc_id
1919
name = "test_acl_update"
2020
ingress = ["ACCEPT#192.168.1.0/24#800#TCP", "ACCEPT#192.168.1.0/24#800-900#TCP",]
2121
egress = ["ACCEPT#192.168.1.0/24#800#TCP", "ACCEPT#192.168.1.0/24#800-900#TCP",]
2222
}
2323

24-
resource "tencentcloud_vpc_acl_attachment" "attachment" {
25-
acl_id = tencentcloud_vpc_acl.foo.id
24+
resource "tencentcloud_vpc_acl_attachment" "example" {
25+
acl_id = tencentcloud_vpc_acl.default.id
2626
subnet_ids = data.tencentcloud_vpc_instances.default.instance_list[0].subnet_ids
2727
}
2828

29-
data "tencentcloud_vpc_acls" "foo" {
29+
data "tencentcloud_vpc_acls" "default" {
3030
name = "test_acl"
3131
}

tencentcloud/data_source_tc_vpc_acls.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func dataSourceTencentCloudVpcAcls() *schema.Resource {
124124
"protocol": {
125125
Type: schema.TypeString,
126126
Computed: true,
127-
Description: "Type of ip protocol.",
127+
Description: "Type of IP protocol.",
128128
},
129129
"port": {
130130
Type: schema.TypeString,
@@ -134,7 +134,7 @@ func dataSourceTencentCloudVpcAcls() *schema.Resource {
134134
"policy": {
135135
Type: schema.TypeString,
136136
Computed: true,
137-
Description: "Rule policy of.",
137+
Description: "Rule policy of Network ACL.",
138138
},
139139
"cidr_block": {
140140
Type: schema.TypeString,
@@ -158,7 +158,7 @@ func dataSourceTencentCloudVpcAcls() *schema.Resource {
158158
"protocol": {
159159
Type: schema.TypeString,
160160
Computed: true,
161-
Description: "Type of ip protocol.",
161+
Description: "Type of IP protocol.",
162162
},
163163
"port": {
164164
Type: schema.TypeString,
@@ -168,7 +168,7 @@ func dataSourceTencentCloudVpcAcls() *schema.Resource {
168168
"policy": {
169169
Type: schema.TypeString,
170170
Computed: true,
171-
Description: "Rule policy of.",
171+
Description: "Rule policy of Network ACL.",
172172
},
173173
"cidr_block": {
174174
Type: schema.TypeString,
@@ -275,7 +275,7 @@ func dataSourceTencentCloudVpcACLRead(d *schema.ResourceData, meta interface{})
275275
d.SetId(helper.DataResourceIdsHash(ids))
276276
err = d.Set("acl_list", aclList)
277277
if err != nil {
278-
log.Printf("[CRITAL]%s provider set acl list fail, reason:%v \n ", logId, err)
278+
log.Printf("[CRITAL]%s provider set ACL list fail, reason:%v \n ", logId, err)
279279
return err
280280
}
281281

tencentcloud/resource_tc_vpc_acl.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ func resourceTencentCloudVpcACL() *schema.Resource {
7676
Elem: &schema.Schema{Type: schema.TypeString},
7777
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,443`, `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`.",
7878
},
79-
8079
//compute
8180
"create_time": {
8281
Type: schema.TypeString,
@@ -151,12 +150,12 @@ func resourceTencentCloudVpcACLRead(d *schema.ResourceData, meta interface{}) er
151150
return err
152151
}
153152
if has == 0 {
154-
log.Printf("[WARN]%s %s\n", logId, "acl has been delete")
153+
log.Printf("[WARN]%s %s\n", logId, "ACL has been delete")
155154
d.SetId("")
156155
return nil
157156
}
158157
if has != 1 {
159-
errRet := fmt.Errorf("one acl_id read get %d acl info", has)
158+
errRet := fmt.Errorf("one acl_id read get %d ACL info", has)
160159
log.Printf("[CRITAL]%s %s\n", logId, errRet.Error())
161160
return errRet
162161
}
@@ -174,7 +173,7 @@ func resourceTencentCloudVpcACLRead(d *schema.ResourceData, meta interface{}) er
174173
*info.EgressEntries[i].CidrBlock,
175174
*info.EgressEntries[i].Port,
176175
*info.EgressEntries[i].Protocol,
177-
}, "#")
176+
}, FILED_SP)
178177
egressList = append(egressList, strings.ToUpper(result))
179178
}
180179

@@ -188,7 +187,7 @@ func resourceTencentCloudVpcACLRead(d *schema.ResourceData, meta interface{}) er
188187
*info.IngressEntries[i].CidrBlock,
189188
*info.IngressEntries[i].Port,
190189
*info.IngressEntries[i].Protocol,
191-
}, "#")
190+
}, FILED_SP)
192191
ingressList = append(ingressList, strings.ToUpper(result))
193192
}
194193
_ = d.Set("egress", egressList)
@@ -269,8 +268,12 @@ func resourceTencentCloudVpcACLUpdate(d *schema.ResourceData, meta interface{})
269268
}
270269
}
271270

272-
if err := service.ModifyNetWorkAclRules(ctx, id, ingress, egress); err != nil {
273-
return err
271+
if d.HasChange("egress") || d.HasChange("ingress") {
272+
if err := service.ModifyNetWorkAclRules(ctx, id, ingress, egress); err != nil {
273+
return err
274+
}
275+
d.SetPartial("ingress")
276+
d.SetPartial("egress")
274277
}
275278
d.Partial(false)
276279

@@ -293,14 +296,12 @@ func resourceTencentCloudVpcACLDelete(d *schema.ResourceData, meta interface{})
293296
}
294297

295298
_, has, err := service.DescribeNetWorkByACLID(ctx, id)
296-
297299
if err != nil {
298300
return err
299301
}
300302

301303
if has > 0 {
302-
return fmt.Errorf("[CRITAL]%s delete network acl : %s failed\n", logId, id)
304+
return fmt.Errorf("[CRITAL]%s delete network ACL : %s failed\n", logId, id)
303305
}
304-
305306
return nil
306307
}

tencentcloud/resource_tc_vpc_acl_attachment.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func resourceTencentCloudVpcAclAttachment() *schema.Resource {
5050
Required: true,
5151
ForceNew: true,
5252
ValidateFunc: validateNotEmpty,
53-
Description: "Id of the attached ACL.",
53+
Description: "ID of the attached ACL.",
5454
},
5555
"subnet_id": {
5656
Type: schema.TypeString,
@@ -81,7 +81,7 @@ func resourceTencentCloudVpcAclAttachmentCreate(d *schema.ResourceData, meta int
8181
return err
8282
}
8383

84-
d.SetId(aclId + "#" + subnetId)
84+
d.SetId(aclId + FILED_SP + subnetId)
8585

8686
return resourceTencentCloudVpcAclAttachmentRead(d, meta)
8787
}
@@ -98,19 +98,14 @@ func resourceTencentCloudVpcAclAttachmentRead(d *schema.ResourceData, meta inter
9898
aclId string
9999
)
100100

101-
if attachmentId == "" {
102-
return fmt.Errorf("attachmentId does not exist")
103-
}
104-
105-
aclId = strings.Split(attachmentId, "#")[0]
106-
101+
aclId = strings.Split(attachmentId, FILED_SP)[0]
107102
results, err := service.DescribeNetWorkAcls(ctx, aclId, "", "")
108103
if err != nil {
109104
return err
110105
}
111106
if len(results) > 0 && len(results[0].SubnetSet) < 1 {
112107
d.SetId("")
113-
return fmt.Errorf("[TECENT_TERRAFORM_CHECK][ACL attachment][Read] check: acl attachment is not create")
108+
return fmt.Errorf("[TECENT_TERRAFORM_CHECK][ACL attachment][Read] check: ACL attachment is not exist")
114109
}
115110
return nil
116111

@@ -127,10 +122,9 @@ func resourceTencentCloudVpcAclAttachmentDelete(d *schema.ResourceData, meta int
127122

128123
err := service.DeleteAclAttachment(ctx, attachmentAcl)
129124
if err != nil {
130-
log.Printf("[CRITAL]%s delete acl attachment failed, reason:%s\n", logId, err.Error())
125+
log.Printf("[CRITAL]%s delete ACL attachment failed, reason:%s\n", logId, err.Error())
131126
return err
132127
}
133-
d.SetId("")
134128

135129
return nil
136130

tencentcloud/resource_tc_vpc_acl_attachment_test.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,13 @@ func testVpcAclAttachmentDestroy(s *terraform.State) error {
3535
if rs.Type != "tencentcloud_vpc_acl_attachment" {
3636
continue
3737
}
38-
err := service.DescribeByAclId(ctx, rs.Primary.ID)
39-
if err == nil {
40-
return fmt.Errorf("[TECENT_TERRAFORM_CHECK][ACL attachment][Destroy] check: acl attachment still exists: %s", rs.Primary.ID)
38+
has, err := service.DescribeByAclId(ctx, rs.Primary.ID)
39+
if err != nil {
40+
return err
41+
}
42+
43+
if has {
44+
return fmt.Errorf("[TECENT_TERRAFORM_CHECK][ACL attachment][Destroy] check: ACL attachment still exists: %s", rs.Primary.ID)
4145
}
4246
}
4347
return nil
@@ -56,9 +60,13 @@ func testVpcAclAttachmentExists(n string) resource.TestCheckFunc {
5660
if rs.Primary.ID == "" {
5761
return fmt.Errorf("[TECENT_TERRAFORM_CHECK][ACL attachment][Exists] check: id is not set")
5862
}
59-
err := service.DescribeByAclId(ctx, rs.Primary.ID)
63+
has, err := service.DescribeByAclId(ctx, rs.Primary.ID)
6064
if err != nil {
61-
return fmt.Errorf("[TECENT_TERRAFORM_CHECK][ACL attachment][Exists] check: still exists: %s", rs.Primary.ID)
65+
return err
66+
}
67+
68+
if !has {
69+
return fmt.Errorf("[TECENT_TERRAFORM_CHECK][ACL attachment][Exists] check: not exists: %s", rs.Primary.ID)
6270
}
6371
return nil
6472
}

tencentcloud/resource_tc_vpc_acl_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"fmt"
66
"testing"
7-
"time"
87

98
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
109
"github.com/hashicorp/terraform-plugin-sdk/terraform"
@@ -119,7 +118,6 @@ func testAccCheckVpcACLDestroy(s *terraform.State) error {
119118
if rs.Type != "tencentcloud_vpc_acl" {
120119
continue
121120
}
122-
time.Sleep(5 * time.Second)
123121
_, has, err := service.DescribeNetWorkByACLID(ctx, rs.Primary.ID)
124122
if err != nil {
125123
return err

tencentcloud/service_tencentcloud_vpc.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3155,7 +3155,7 @@ func (me *VpcService) DescribeNetWorkAcls(ctx context.Context, aclID, vpcID, nam
31553155
return
31563156
}
31573157

3158-
func (me *VpcService) DescribeByAclId(ctx context.Context, attachmentAcl string) (errRet error) {
3158+
func (me *VpcService) DescribeByAclId(ctx context.Context, attachmentAcl string) (has bool, errRet error) {
31593159
var (
31603160
logId = getLogId(ctx)
31613161
request = vpc.NewDisassociateNetworkAclSubnetsRequest()
@@ -3177,12 +3177,15 @@ func (me *VpcService) DescribeByAclId(ctx context.Context, attachmentAcl string)
31773177

31783178
results, err := me.DescribeNetWorkAcls(ctx, aclId, "", "")
31793179
if err != nil {
3180-
return err
3180+
errRet = err
3181+
return
31813182
}
31823183
if len(results) < 1 || len(results[0].SubnetSet) < 1 {
3183-
return fmt.Errorf("[TECENT_TERRAFORM_CHECK][ACL attachment][Exists] check: Acl id is not set")
3184+
return
31843185
}
3185-
return nil
3186+
3187+
has = true
3188+
return
31863189
}
31873190

31883191
func (me *VpcService) DeleteAclAttachment(ctx context.Context, attachmentAcl string) (errRet error) {

website/docs/d/vpc_acls.html.markdown

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ In addition to all arguments above, the following attributes are exported:
4343
* `egress` - Outbound rules of the network ACL.
4444
* `cidr_block` - An IP address network or segment.
4545
* `description` - Rule description.
46-
* `policy` - Rule policy of.
46+
* `policy` - Rule policy of Network ACL.
4747
* `port` - Range of the port.
48-
* `protocol` - Type of ip protocol.
48+
* `protocol` - Type of IP protocol.
4949
* `id` - ID of the network ACL instance.
5050
* `ingress` - Inbound rules of the network ACL.
5151
* `cidr_block` - An IP address network or segment.
5252
* `description` - Rule description.
53-
* `policy` - Rule policy of.
53+
* `policy` - Rule policy of Network ACL.
5454
* `port` - Range of the port.
55-
* `protocol` - Type of ip protocol.
55+
* `protocol` - Type of IP protocol.
5656
* `name` - Name of the network ACL.
5757
* `subnets` - Subnets associated with the network ACL.
5858
* `cidr_block` - The IPv4 CIDR of the subnet.

website/docs/r/vpc_acl_attachment.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Provide a resource to attach an existing subnet to Network ACL.
1818

1919
The following arguments are supported:
2020

21-
* `acl_id` - (Required, ForceNew) Id of the attached ACL.
21+
* `acl_id` - (Required, ForceNew) ID of the attached ACL.
2222
* `subnet_id` - (Required, ForceNew) The Subnet instance ID.
2323

2424
## Attributes Reference

0 commit comments

Comments
 (0)