@@ -83,9 +83,9 @@ func ResourceTencentCloudCosBucketInventory() *schema.Resource {
83
83
},
84
84
},
85
85
"optional_fields" : {
86
- Type : schema .TypeList ,
87
- MaxItems : 1 ,
88
- Optional : true ,
86
+ Type : schema .TypeList ,
87
+ MaxItems : 1 ,
88
+ Optional : true ,
89
89
Description : "Analysis items to include in the inventory result ." ,
90
90
Elem : & schema.Resource {
91
91
Schema : map [string ]* schema.Schema {
@@ -175,73 +175,96 @@ func resourceTencentCloudCosBucketInventoryCreate(d *schema.ResourceData, meta i
175
175
isEnabled := d .Get ("is_enabled" ).(string )
176
176
includedObjectVersions := d .Get ("included_object_versions" ).(string )
177
177
178
- var filter cos.BucketInventoryFilter
179
- if v , ok := d .GetOk ("filter" ); ok && len (v .([]interface {})) != 0 {
180
- var period cos.BucketInventoryFilterPeriod
181
- filterMap := v .([]interface {})[0 ].(map [string ]interface {})
182
- if v , ok := filterMap ["period" ]; ok && len (v .([]interface {})) > 0 {
183
- periodMap := v .([]interface {})[0 ].(map [string ]interface {})
184
- if v , ok := periodMap ["start_time" ]; ok && v .(string ) != "" {
185
- vStr , err := strconv .ParseInt (v .(string ), 10 , 64 )
186
- if err != nil {
187
- return err
188
- }
189
- period .StartTime = vStr
178
+ filter := cos.BucketInventoryFilter {}
179
+ if v , ok := d .GetOk ("filter" ); ok {
180
+ for _ , item := range v .([]interface {}) {
181
+ dMap := item .(map [string ]interface {})
182
+ if v , ok := dMap ["prefix" ]; ok {
183
+ filter .Prefix = v .(string )
190
184
}
191
- if v , ok := periodMap ["end_time" ]; ok && v .(string ) != "" {
192
- vStr , err := strconv .ParseInt (v .(string ), 10 , 64 )
193
- if err != nil {
194
- return err
185
+
186
+ if v , ok := dMap ["period" ]; ok {
187
+ for _ , item := range v .([]interface {}) {
188
+ periodMap := item .(map [string ]interface {})
189
+ period := cos.BucketInventoryFilterPeriod {}
190
+ if v , ok := periodMap ["start_time" ]; ok && v .(string ) != "" {
191
+ vStr , err := strconv .ParseInt (v .(string ), 10 , 64 )
192
+ if err != nil {
193
+ return err
194
+ }
195
+
196
+ period .StartTime = vStr
197
+ }
198
+
199
+ if v , ok := periodMap ["end_time" ]; ok && v .(string ) != "" {
200
+ vStr , err := strconv .ParseInt (v .(string ), 10 , 64 )
201
+ if err != nil {
202
+ return err
203
+ }
204
+
205
+ period .EndTime = vStr
206
+ }
207
+
208
+ filter .Period = & period
195
209
}
196
- period .EndTime = vStr
197
210
}
198
- filter .Period = & period
199
- }
200
- if v , ok := filterMap ["prefix" ]; ok {
201
- filter .Prefix = v .(string )
202
211
}
203
212
}
204
- var optionalFields cos.BucketInventoryOptionalFields
205
- if v , ok := d .GetOk ("optional_fields" ); ok && len (v .([]interface {})) != 0 {
206
- optionalFieldsMap := v .([]interface {})[0 ].(map [string ]interface {})
207
- if v , ok := optionalFieldsMap ["fields" ]; ok {
208
- optionalFields .BucketInventoryFields = make ([]string , 0 )
209
- for _ , field := range v .(* schema.Set ).List () {
210
- optionalFields .BucketInventoryFields = append (optionalFields .BucketInventoryFields , field .(string ))
213
+
214
+ optionalFields := cos.BucketInventoryOptionalFields {}
215
+ if v , ok := d .GetOk ("optional_fields" ); ok {
216
+ for _ , item := range v .([]interface {}) {
217
+ dMap := item .(map [string ]interface {})
218
+ if v , ok := dMap ["fields" ]; ok {
219
+ fields := v .(* schema.Set ).List ()
220
+ for _ , field := range fields {
221
+ optionalFields .BucketInventoryFields = append (optionalFields .BucketInventoryFields , field .(string ))
222
+ }
211
223
}
212
224
}
213
225
}
214
226
215
- var schedule cos.BucketInventorySchedule
216
- if v , ok := d .GetOk ("schedule" ); ok && len (v .([]interface {})) != 0 {
217
- scheduleMap := v .([]interface {})[0 ].(map [string ]interface {})
218
- if v , ok := scheduleMap ["frequency" ]; ok {
219
- schedule .Frequency = v .(string )
227
+ schedule := cos.BucketInventorySchedule {}
228
+ if v , ok := d .GetOk ("schedule" ); ok {
229
+ for _ , item := range v .([]interface {}) {
230
+ dMap := item .(map [string ]interface {})
231
+ if v , ok := dMap ["frequency" ]; ok {
232
+ schedule .Frequency = v .(string )
233
+ }
220
234
}
221
235
}
222
236
223
- var destination cos.BucketInventoryDestination
224
- if v , ok := d .GetOk ("destination" ); ok && len (v .([]interface {})) != 0 {
225
- destinationMap := v .([]interface {})[0 ].(map [string ]interface {})
226
- if v , ok := destinationMap ["bucket" ]; ok {
227
- destination .Bucket = v .(string )
228
- }
229
- if v , ok := destinationMap ["account_id" ]; ok {
230
- destination .AccountId = v .(string )
231
- }
232
- if v , ok := destinationMap ["prefix" ]; ok {
233
- destination .Prefix = v .(string )
234
- }
235
- if v , ok := destinationMap ["format" ]; ok {
236
- destination .Format = v .(string )
237
- }
238
- if v , ok := destinationMap ["encryption" ]; ok && len (v .([]interface {})) > 0 {
239
- encryptionMap := v .([]interface {})[0 ].(map [string ]interface {})
240
- if v , ok := encryptionMap ["sse_cos" ]; ok {
241
- destination .Encryption = & cos.BucketInventoryEncryption {
242
- SSECOS : v .(string ),
243
- }
237
+ destination := cos.BucketInventoryDestination {}
238
+ if v , ok := d .GetOk ("destination" ); ok {
239
+ for _ , item := range v .([]interface {}) {
240
+ dMap := item .(map [string ]interface {})
241
+ if v , ok := dMap ["bucket" ]; ok {
242
+ destination .Bucket = v .(string )
243
+ }
244
+
245
+ if v , ok := dMap ["account_id" ]; ok {
246
+ destination .AccountId = v .(string )
247
+ }
248
+
249
+ if v , ok := dMap ["prefix" ]; ok {
250
+ destination .Prefix = v .(string )
251
+ }
244
252
253
+ if v , ok := dMap ["format" ]; ok {
254
+ destination .Format = v .(string )
255
+ }
256
+
257
+ if v , ok := dMap ["encryption" ]; ok {
258
+ for _ , item := range v .([]interface {}) {
259
+ if item != nil {
260
+ dMap := item .(map [string ]interface {})
261
+ if v , ok := dMap ["sse_cos" ]; ok {
262
+ destination .Encryption = & cos.BucketInventoryEncryption {
263
+ SSECOS : v .(string ),
264
+ }
265
+ }
266
+ }
267
+ }
245
268
}
246
269
}
247
270
}
@@ -364,73 +387,96 @@ func resourceTencentCloudCosBucketInventoryUpdate(d *schema.ResourceData, meta i
364
387
isEnabled := d .Get ("is_enabled" ).(string )
365
388
includedObjectVersions := d .Get ("included_object_versions" ).(string )
366
389
367
- var filter cos.BucketInventoryFilter
368
- if v , ok := d .GetOk ("filter" ); ok && len (v .([]interface {})) != 0 {
369
- var period cos.BucketInventoryFilterPeriod
370
- filterMap := v .([]interface {})[0 ].(map [string ]interface {})
371
- if v , ok := filterMap ["period" ]; ok && len (v .([]interface {})) > 0 {
372
- periodMap := v .([]interface {})[0 ].(map [string ]interface {})
373
- if v , ok := periodMap ["start_time" ]; ok && v .(string ) != "" {
374
- vStr , err := strconv .ParseInt (v .(string ), 10 , 64 )
375
- if err != nil {
376
- return err
377
- }
378
- period .StartTime = vStr
390
+ filter := cos.BucketInventoryFilter {}
391
+ if v , ok := d .GetOk ("filter" ); ok {
392
+ for _ , item := range v .([]interface {}) {
393
+ dMap := item .(map [string ]interface {})
394
+ if v , ok := dMap ["prefix" ]; ok {
395
+ filter .Prefix = v .(string )
379
396
}
380
- if v , ok := periodMap ["end_time" ]; ok && v .(string ) != "" {
381
- vStr , err := strconv .ParseInt (v .(string ), 10 , 64 )
382
- if err != nil {
383
- return err
397
+
398
+ if v , ok := dMap ["period" ]; ok {
399
+ for _ , item := range v .([]interface {}) {
400
+ periodMap := item .(map [string ]interface {})
401
+ period := cos.BucketInventoryFilterPeriod {}
402
+ if v , ok := periodMap ["start_time" ]; ok && v .(string ) != "" {
403
+ vStr , err := strconv .ParseInt (v .(string ), 10 , 64 )
404
+ if err != nil {
405
+ return err
406
+ }
407
+
408
+ period .StartTime = vStr
409
+ }
410
+
411
+ if v , ok := periodMap ["end_time" ]; ok && v .(string ) != "" {
412
+ vStr , err := strconv .ParseInt (v .(string ), 10 , 64 )
413
+ if err != nil {
414
+ return err
415
+ }
416
+
417
+ period .EndTime = vStr
418
+ }
419
+
420
+ filter .Period = & period
384
421
}
385
- period .EndTime = vStr
386
422
}
387
- filter .Period = & period
388
- }
389
- if v , ok := filterMap ["prefix" ]; ok {
390
- filter .Prefix = v .(string )
391
423
}
392
424
}
393
- var optionalFields cos.BucketInventoryOptionalFields
394
- if v , ok := d .GetOk ("optional_fields" ); ok && len (v .([]interface {})) != 0 {
395
- optionalFieldsMap := v .([]interface {})[0 ].(map [string ]interface {})
396
- if v , ok := optionalFieldsMap ["fields" ]; ok {
397
- optionalFields .BucketInventoryFields = make ([]string , 0 )
398
- for _ , field := range v .(* schema.Set ).List () {
399
- optionalFields .BucketInventoryFields = append (optionalFields .BucketInventoryFields , field .(string ))
425
+
426
+ optionalFields := cos.BucketInventoryOptionalFields {}
427
+ if v , ok := d .GetOk ("optional_fields" ); ok {
428
+ for _ , item := range v .([]interface {}) {
429
+ dMap := item .(map [string ]interface {})
430
+ if v , ok := dMap ["fields" ]; ok {
431
+ fields := v .(* schema.Set ).List ()
432
+ for _ , field := range fields {
433
+ optionalFields .BucketInventoryFields = append (optionalFields .BucketInventoryFields , field .(string ))
434
+ }
400
435
}
401
436
}
402
437
}
403
438
404
- var schedule cos.BucketInventorySchedule
405
- if v , ok := d .GetOk ("schedule" ); ok && len (v .([]interface {})) != 0 {
406
- scheduleMap := v .([]interface {})[0 ].(map [string ]interface {})
407
- if v , ok := scheduleMap ["frequency" ]; ok {
408
- schedule .Frequency = v .(string )
439
+ schedule := cos.BucketInventorySchedule {}
440
+ if v , ok := d .GetOk ("schedule" ); ok {
441
+ for _ , item := range v .([]interface {}) {
442
+ dMap := item .(map [string ]interface {})
443
+ if v , ok := dMap ["frequency" ]; ok {
444
+ schedule .Frequency = v .(string )
445
+ }
409
446
}
410
447
}
411
448
412
- var destination cos.BucketInventoryDestination
413
- if v , ok := d .GetOk ("destination" ); ok && len (v .([]interface {})) != 0 {
414
- destinationMap := v .([]interface {})[0 ].(map [string ]interface {})
415
- if v , ok := destinationMap ["bucket" ]; ok {
416
- destination .Bucket = v .(string )
417
- }
418
- if v , ok := destinationMap ["account_id" ]; ok {
419
- destination .AccountId = v .(string )
420
- }
421
- if v , ok := destinationMap ["prefix" ]; ok {
422
- destination .Prefix = v .(string )
423
- }
424
- if v , ok := destinationMap ["format" ]; ok {
425
- destination .Format = v .(string )
426
- }
427
- if v , ok := destinationMap ["encryption" ]; ok && len (v .([]interface {})) > 0 {
428
- encryptionMap := v .([]interface {})[0 ].(map [string ]interface {})
429
- if v , ok := encryptionMap ["sse_cos" ]; ok {
430
- destination .Encryption = & cos.BucketInventoryEncryption {
431
- SSECOS : v .(string ),
432
- }
449
+ destination := cos.BucketInventoryDestination {}
450
+ if v , ok := d .GetOk ("destination" ); ok {
451
+ for _ , item := range v .([]interface {}) {
452
+ dMap := item .(map [string ]interface {})
453
+ if v , ok := dMap ["bucket" ]; ok {
454
+ destination .Bucket = v .(string )
455
+ }
456
+
457
+ if v , ok := dMap ["account_id" ]; ok {
458
+ destination .AccountId = v .(string )
459
+ }
433
460
461
+ if v , ok := dMap ["prefix" ]; ok {
462
+ destination .Prefix = v .(string )
463
+ }
464
+
465
+ if v , ok := dMap ["format" ]; ok {
466
+ destination .Format = v .(string )
467
+ }
468
+
469
+ if v , ok := dMap ["encryption" ]; ok {
470
+ for _ , item := range v .([]interface {}) {
471
+ if item != nil {
472
+ dMap := item .(map [string ]interface {})
473
+ if v , ok := dMap ["sse_cos" ]; ok {
474
+ destination .Encryption = & cos.BucketInventoryEncryption {
475
+ SSECOS : v .(string ),
476
+ }
477
+ }
478
+ }
479
+ }
434
480
}
435
481
}
436
482
}
0 commit comments