Skip to content

Commit e941777

Browse files
author
“guojunchu”
committed
Merge remote-tracking branch 'origin/master'
# Conflicts: # tencentcloud/data_source_tc_vpc_acls.go # tencentcloud/resource_tc_vpc_acl.go # tencentcloud/service_tencentcloud_vpc.go
1 parent 16831d6 commit e941777

File tree

3 files changed

+22
-42
lines changed

3 files changed

+22
-42
lines changed

tencentcloud/resource_tc_vpc_acl_attachment.go

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@ import (
3131
"fmt"
3232
"log"
3333
"strings"
34-
"time"
3534

3635
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
3736
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
38-
"github.com/terraform-providers/terraform-provider-tencentcloud/tencentcloud/internal/helper"
3937
)
4038

4139
func resourceTencentCloudVpcAclAttachment() *schema.Resource {
@@ -49,19 +47,17 @@ func resourceTencentCloudVpcAclAttachment() *schema.Resource {
4947

5048
Schema: map[string]*schema.Schema{
5149
"acl_id": {
50+
Type: schema.TypeString,
51+
Required: true,
52+
ForceNew: true,
53+
ValidateFunc: validateNotEmpty,
54+
Description: "Id of the attached ACL.",
55+
},
56+
"subnet_id": {
5257
Type: schema.TypeString,
5358
Required: true,
5459
ForceNew: true,
55-
Description: "Id of the attached ACL.",
56-
},
57-
"subnet_ids": {
58-
Type: schema.TypeList,
59-
Required: true,
60-
ForceNew: true,
61-
Elem: &schema.Schema{
62-
Type: schema.TypeString,
63-
},
64-
Description: "ID list of the Subnet instance ID.",
60+
Description: " the Subnet instance ID.",
6561
},
6662
},
6763
}
@@ -75,28 +71,23 @@ func resourceTencentCloudVpcAclAttachmentCreate(d *schema.ResourceData, meta int
7571
service = VpcService{client: meta.(*TencentCloudClient).apiV3Conn}
7672
aclId string
7773
subnetIds []string
78-
sub_id string
74+
subnetId string
7975
)
8076

8177
if temp, ok := d.GetOk("acl_id"); ok {
8278
aclId = temp.(string)
83-
if len(aclId) < 1 {
84-
return fmt.Errorf("acl_id should be not empty string")
85-
}
8679
}
87-
if temp, ok := d.GetOk("subnet_ids"); ok {
88-
subnetIds = helper.InterfacesStrings(temp.([]interface{}))
80+
if temp, ok := d.GetOk("subnet_id"); ok {
81+
subnetId = temp.(string)
8982
}
83+
subnetIds = append(subnetIds, subnetId)
9084

9185
err := service.AssociateAclSubnets(ctx, aclId, subnetIds)
9286
if err != nil {
9387
return err
9488
}
9589

96-
for _, temp_id := range subnetIds {
97-
sub_id = sub_id + "#" + temp_id
98-
}
99-
d.SetId(aclId + "#" + sub_id)
90+
d.SetId(aclId + "#" + subnetId)
10091

10192
aclAttachmentId := d.Id()
10293
err = resource.Retry(readRetryTimeout, func() *resource.RetryError {
@@ -110,7 +101,6 @@ func resourceTencentCloudVpcAclAttachmentCreate(d *schema.ResourceData, meta int
110101
log.Printf("[CRITAL]%s read acl attachment failed, reason:%s\n", logId, err.Error())
111102
return err
112103
}
113-
time.Sleep(10 * time.Second)
114104

115105
return resourceTencentCloudVpcAclAttachmentRead(d, meta)
116106
}
@@ -158,6 +148,7 @@ func resourceTencentCloudVpcAclAttachmentDelete(d *schema.ResourceData, meta int
158148
log.Printf("[CRITAL]%s delete acl attachment failed, reason:%s\n", logId, err.Error())
159149
return err
160150
}
151+
d.SetId("")
161152

162153
return nil
163154

tencentcloud/resource_tc_vpc_acl_attachment_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ func testVpcAclAttachmentExists(n string) resource.TestCheckFunc {
6666

6767
const testAclAttachment_basic = `
6868
data "tencentcloud_vpc_instances" "id_instances" {
69+
name = "acl_test"
6970
}
7071
resource "tencentcloud_vpc_acl" "foo" {
7172
vpc_id = data.tencentcloud_vpc_instances.id_instances.instance_list.0.vpc_id
@@ -81,6 +82,6 @@ resource "tencentcloud_vpc_acl" "foo" {
8182
}
8283
resource "tencentcloud_vpc_acl_attachment" "attachment"{
8384
acl_id = tencentcloud_vpc_acl.foo.id
84-
subnet_ids = data.tencentcloud_vpc_instances.id_instances.instance_list[0].subnet_ids
85+
subnet_id = data.tencentcloud_vpc_instances.id_instances.instance_list[0].subnet_ids[0]
8586
}
8687
`

tencentcloud/service_tencentcloud_vpc.go

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3221,11 +3221,8 @@ func (me *VpcService) DescribeByAclId(ctx context.Context, attachmentAcl string)
32213221
return
32223222
}
32233223

3224-
for i, v := range strings.Split(attachmentAcl, "#") {
3225-
if i == 0 {
3226-
aclId = v
3227-
}
3228-
}
3224+
aclId = strings.Split(attachmentAcl, "#")[0]
3225+
32293226
results, err := me.DescribeNetWorkAcls(ctx, aclId, "", "")
32303227
if err != nil {
32313228
return err
@@ -3241,25 +3238,16 @@ func (me *VpcService) DeleteAclAttachment(ctx context.Context, attachmentAcl str
32413238
logId = getLogId(ctx)
32423239
request = vpc.NewDisassociateNetworkAclSubnetsRequest()
32433240
err error
3244-
3245-
subIds []*string
3246-
aclId string
32473241
)
32483242

32493243
if attachmentAcl == "" {
3250-
errRet = fmt.Errorf("DeleteRouteTable can not invoke by empty routeTableId.")
3244+
errRet = fmt.Errorf("DeleteRouteTable can not invoke by empty NetworkAclId.")
32513245
return
32523246
}
32533247

3254-
for i, v := range strings.Split(attachmentAcl, "#") {
3255-
if i == 0 {
3256-
aclId = v
3257-
} else {
3258-
subIds = append(subIds, &v)
3259-
}
3260-
}
3261-
request.NetworkAclId = &aclId
3262-
request.SubnetIds = subIds
3248+
items := strings.Split(attachmentAcl, "#")
3249+
request.NetworkAclId = &items[0]
3250+
request.SubnetIds = helper.Strings(items[1:])
32633251

32643252
err = resource.Retry(writeRetryTimeout, func() *resource.RetryError {
32653253
ratelimit.Check(request.GetAction())

0 commit comments

Comments
 (0)