@@ -93,18 +93,13 @@ func resourceTencentCloudVpcACLCreate(d *schema.ResourceData, meta interface{})
93
93
logId = getLogId (contextNil )
94
94
ctx = context .WithValue (context .TODO (), logIdKey , logId )
95
95
vpcService = VpcService {client : meta .(* TencentCloudClient ).apiV3Conn }
96
- vpcID string
97
- name string
98
- ingress []VpcACLRule
99
- egress []VpcACLRule
96
+
97
+ ingress []VpcACLRule
98
+ egress []VpcACLRule
99
+ vpcID = d .Get ("vpc_id" ).(string )
100
+ name = d .Get ("name" ).(string )
100
101
)
101
102
102
- if temp , ok := d .GetOk ("vpc_id" ); ok {
103
- vpcID = temp .(string )
104
- }
105
- if temp , ok := d .GetOk ("name" ); ok {
106
- name = temp .(string )
107
- }
108
103
if temp , ok := d .GetOk ("ingress" ); ok {
109
104
ingressStrs := helper .InterfacesStrings (temp .([]interface {}))
110
105
for _ , ingressStr := range ingressStrs {
@@ -131,13 +126,12 @@ func resourceTencentCloudVpcACLCreate(d *schema.ResourceData, meta interface{})
131
126
return err
132
127
}
133
128
129
+ d .SetId (aclID )
134
130
err = vpcService .AttachRulesToACL (ctx , aclID , ingress , egress )
135
131
if err != nil {
136
132
return err
137
133
}
138
134
139
- d .SetId (aclID )
140
-
141
135
return resourceTencentCloudVpcACLRead (d , meta )
142
136
}
143
137
@@ -152,7 +146,7 @@ func resourceTencentCloudVpcACLRead(d *schema.ResourceData, meta interface{}) er
152
146
id = d .Id ()
153
147
)
154
148
155
- vpcID , createTime , has , err := service .DescribeNetWorkByACLID (ctx , id )
149
+ info , has , err := service .DescribeNetWorkByACLID (ctx , id )
156
150
if err != nil {
157
151
return err
158
152
}
@@ -167,128 +161,111 @@ func resourceTencentCloudVpcACLRead(d *schema.ResourceData, meta interface{}) er
167
161
return errRet
168
162
}
169
163
170
- _ = d .Set ("vpc_id" , vpcID )
171
- _ = d .Set ("create_time" , createTime )
164
+ _ = d .Set ("vpc_id" , info .VpcId )
165
+ _ = d .Set ("create_time" , info .CreatedTime )
166
+ _ = d .Set ("name" , info .NetworkAclName )
167
+ egressList := make ([]map [string ]interface {}, 0 , len (info .EgressEntries ))
168
+ for i := range info .EgressEntries {
169
+ result := map [string ]interface {}{
170
+ "protocol" : info .EgressEntries [i ].Protocol ,
171
+ "port" : info .EgressEntries [i ].Port ,
172
+ "cidr_ip" : info .EgressEntries [i ].CidrBlock ,
173
+ "policy" : info .EgressEntries [i ].Action ,
174
+ }
175
+ egressList = append (egressList , result )
176
+ }
177
+
178
+ ingressList := make ([]map [string ]interface {}, 0 , len (info .IngressEntries ))
179
+ for i := range info .IngressEntries {
180
+ result := map [string ]interface {}{
181
+ "protocol" : info .IngressEntries [i ].Protocol ,
182
+ "port" : info .IngressEntries [i ].Port ,
183
+ "cidr_ip" : info .IngressEntries [i ].CidrBlock ,
184
+ "policy" : info .IngressEntries [i ].Action ,
185
+ }
186
+ ingressList = append (ingressList , result )
187
+ }
188
+ _ = d .Set ("egress" , egressList )
189
+ _ = d .Set ("ingress" , ingressList )
190
+
172
191
return nil
173
192
}
174
193
175
194
func resourceTencentCloudVpcACLUpdate (d * schema.ResourceData , meta interface {}) error {
176
195
defer logElapsed ("resource.tencentcloud_vpc_acl.update" )()
177
196
178
- const (
179
- DeleteAll int8 = iota
180
- DeleteIngress
181
- DeleteEgress
182
- )
183
-
184
197
var (
185
198
logId = getLogId (contextNil )
186
199
ctx = context .WithValue (context .TODO (), logIdKey , logId )
187
200
service = VpcService {client : meta .(* TencentCloudClient ).apiV3Conn }
188
201
id = d .Id ()
189
202
190
- name * string
191
- ingress []VpcACLRule
192
- egress []VpcACLRule
193
- deleteIngress bool
194
- deleteEgress bool
203
+ name * string
204
+ ingress []VpcACLRule
205
+ egress []VpcACLRule
195
206
)
196
207
208
+ d .Partial (true )
209
+
197
210
if d .HasChange ("name" ) {
198
211
name = helper .String (d .Get ("name" ).(string ))
199
212
err := service .ModifyVpcNetworkAcl (ctx , & id , name )
200
213
if err != nil {
201
214
return nil
202
215
}
216
+
217
+ d .SetPartial ("name" )
203
218
}
219
+
204
220
if d .HasChange ("ingress" ) {
205
- if raw , ok := d .GetOk ("ingress" ); ok {
206
- oldIngress := helper .InterfacesStrings (raw .([]interface {}))
207
- for _ , ingressStr := range oldIngress {
208
- liteRule , err := parseACLRule (ingressStr )
209
- if err != nil {
210
- return err
211
- }
212
- ingress = append (ingress , liteRule )
221
+ _ , new := d .GetChange ("ingress" )
222
+ if len (new .([]interface {})) == 0 {
223
+ //del ingress
224
+ ingress = []VpcACLRule {
225
+ {
226
+ protocol : "all" ,
227
+ cidrIp : "0.0.0.0/0" ,
228
+ action : "DROP" ,
229
+ },
213
230
}
214
231
} else {
215
- old , _ := d .GetChange ("ingress" )
216
- oldIngress := helper .InterfacesStrings (old .([]interface {}))
217
- for _ , ingressStr := range oldIngress {
232
+ newIngress := helper .InterfacesStrings (new .([]interface {}))
233
+ for _ , ingressStr := range newIngress {
218
234
liteRule , err := parseACLRule (ingressStr )
219
235
if err != nil {
220
236
return err
221
237
}
222
238
ingress = append (ingress , liteRule )
223
239
}
224
-
225
- deleteIngress = true
226
240
}
227
241
}
228
242
229
243
if d .HasChange ("egress" ) {
230
- if raw , ok := d .GetOk ("egress" ); ok {
231
- oldEgress := helper .InterfacesStrings (raw .([]interface {}))
232
- for _ , egressStr := range oldEgress {
233
- liteRule , err := parseACLRule (egressStr )
234
- if err != nil {
235
- return err
236
- }
237
- egress = append (egress , liteRule )
244
+ _ , new := d .GetChange ("egress" )
245
+ if len (new .([]interface {})) == 0 {
246
+ //del ingress
247
+ egress = []VpcACLRule {
248
+ {
249
+ protocol : "all" ,
250
+ cidrIp : "0.0.0.0/0" ,
251
+ action : "DROP" ,
252
+ },
238
253
}
239
254
} else {
240
- old , _ := d .GetChange ("egress" )
241
- oldEgress := helper .InterfacesStrings (old .([]interface {}))
242
- for _ , egressStr := range oldEgress {
255
+ newIngress := helper .InterfacesStrings (new .([]interface {}))
256
+ for _ , egressStr := range newIngress {
243
257
liteRule , err := parseACLRule (egressStr )
244
258
if err != nil {
245
259
return err
246
260
}
247
261
egress = append (egress , liteRule )
248
262
}
249
-
250
- deleteEgress = true
251
263
}
252
264
}
253
265
254
- d .Partial (true )
255
-
256
- if deleteIngress && deleteEgress {
257
- if err := service .DeleteACLRulesByChoose (ctx , id , nil , nil , DeleteAll ); err != nil {
258
- return err
259
- }
260
-
261
- d .Partial (false )
262
-
263
- return resourceTencentCloudVpcACLRead (d , meta )
264
- }
265
-
266
- if deleteIngress {
267
- if err := service .DeleteACLRulesByChoose (ctx , id , ingress , nil , DeleteIngress ); err != nil {
268
- return err
269
- }
270
-
271
- d .SetPartial ("ingress" )
272
-
273
- ingress = nil
274
- }
275
-
276
- if deleteEgress {
277
- if err := service .DeleteACLRulesByChoose (ctx , id , nil , egress , DeleteEgress ); err != nil {
278
- return err
279
- }
280
-
281
- d .SetPartial ("egress" )
282
-
283
- egress = nil
284
- }
285
-
286
- if len (ingress ) > 0 || len (egress ) > 0 {
287
- if err := service .ModifyNetWorkAclRules (ctx , id , ingress , egress ); err != nil {
288
- return err
289
- }
266
+ if err := service .ModifyNetWorkAclRules (ctx , id , ingress , egress ); err != nil {
267
+ return err
290
268
}
291
-
292
269
d .Partial (false )
293
270
294
271
return resourceTencentCloudVpcACLRead (d , meta )
@@ -309,7 +286,7 @@ func resourceTencentCloudVpcACLDelete(d *schema.ResourceData, meta interface{})
309
286
return err
310
287
}
311
288
312
- _ , _ , has , err := service .DescribeNetWorkByACLID (ctx , id )
289
+ _ , has , err := service .DescribeNetWorkByACLID (ctx , id )
313
290
314
291
if err != nil {
315
292
return err
0 commit comments