@@ -39,6 +39,8 @@ import (
3939 "log"
4040 "strings"
4141
42+ vpc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc/v20170312"
43+
4244 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
4345 "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
4446)
@@ -190,28 +192,77 @@ func resourceTencentCloudVpcACLRead(d *schema.ResourceData, meta interface{}) er
190192 _ = d .Set ("name" , info .NetworkAclName )
191193 egressList := make ([]string , 0 , len (info .EgressEntries ))
192194 for i := range info .EgressEntries {
193- if info .EgressEntries [i ].Port == nil || * info .EgressEntries [i ].Port == "" {
195+ // remove default rule
196+ if CheckIfDefaultRule (info .EgressEntries [i ]) {
194197 continue
195198 }
199+
200+ var (
201+ action string
202+ cidrBlock string
203+ port string
204+ protocol string
205+ )
206+
207+ if info .EgressEntries [i ].Action != nil {
208+ action = * info .EgressEntries [i ].Action
209+ }
210+ if info .EgressEntries [i ].CidrBlock != nil {
211+ cidrBlock = * info .EgressEntries [i ].CidrBlock
212+ }
213+ if info .EgressEntries [i ].Port == nil || * info .EgressEntries [i ].Port == "" {
214+ port = "ALL"
215+ } else {
216+ port = * info .EgressEntries [i ].Port
217+ }
218+ if info .EgressEntries [i ].Protocol != nil {
219+ protocol = * info .EgressEntries [i ].Protocol
220+ }
221+
196222 result := strings .Join ([]string {
197- * info . EgressEntries [ i ]. Action ,
198- * info . EgressEntries [ i ]. CidrBlock ,
199- * info . EgressEntries [ i ]. Port ,
200- * info . EgressEntries [ i ]. Protocol ,
223+ action ,
224+ cidrBlock ,
225+ port ,
226+ protocol ,
201227 }, FILED_SP )
228+
202229 egressList = append (egressList , strings .ToUpper (result ))
203230 }
204231
205232 ingressList := make ([]string , 0 , len (info .IngressEntries ))
206233 for i := range info .IngressEntries {
207- if info .IngressEntries [i ].Port == nil || * info .IngressEntries [i ].Port == "" {
234+ // remove default rule
235+ if CheckIfDefaultRule (info .IngressEntries [i ]) {
208236 continue
209237 }
238+
239+ var (
240+ action string
241+ cidrBlock string
242+ port string
243+ protocol string
244+ )
245+
246+ if info .IngressEntries [i ].Action != nil {
247+ action = * info .IngressEntries [i ].Action
248+ }
249+ if info .IngressEntries [i ].CidrBlock != nil {
250+ cidrBlock = * info .IngressEntries [i ].CidrBlock
251+ }
252+ if info .IngressEntries [i ].Port == nil || * info .IngressEntries [i ].Port == "" {
253+ port = "ALL"
254+ } else {
255+ port = * info .IngressEntries [i ].Port
256+ }
257+ if info .IngressEntries [i ].Protocol != nil {
258+ protocol = * info .IngressEntries [i ].Protocol
259+ }
260+
210261 result := strings .Join ([]string {
211- * info . IngressEntries [ i ]. Action ,
212- * info . IngressEntries [ i ]. CidrBlock ,
213- * info . IngressEntries [ i ]. Port ,
214- * info . IngressEntries [ i ]. Protocol ,
262+ action ,
263+ cidrBlock ,
264+ port ,
265+ protocol ,
215266 }, FILED_SP )
216267 ingressList = append (ingressList , strings .ToUpper (result ))
217268 }
@@ -350,3 +401,19 @@ func resourceTencentCloudVpcACLDelete(d *schema.ResourceData, meta interface{})
350401 }
351402 return nil
352403}
404+
405+ func CheckIfDefaultRule (aclEntry * vpc.NetworkAclEntry ) bool {
406+ // remove default ipv6 rule
407+ if aclEntry .Protocol != nil && * aclEntry .Protocol == "all" &&
408+ aclEntry .Ipv6CidrBlock != nil && * aclEntry .Ipv6CidrBlock == "::/0" &&
409+ aclEntry .Action != nil && * aclEntry .Action == "Accept" {
410+ return true
411+ }
412+ // remove default cidr rule
413+ if aclEntry .Protocol != nil && * aclEntry .Protocol == "all" &&
414+ aclEntry .CidrBlock != nil && * aclEntry .CidrBlock == "0.0.0.0/0" &&
415+ aclEntry .Action != nil && * aclEntry .Action == "Drop" {
416+ return true
417+ }
418+ return false
419+ }
0 commit comments