Skip to content

Commit e6cc362

Browse files
authored
resource/aws_s3_bucket_inventory: Prevent crashes with empty destination, filter, and schedule configuration blocks (#17055)
Reference: #16952 Reference: #16953 Output from acceptance testing: ``` --- PASS: TestAccAWSS3BucketInventory_encryptWithSSEKMS (26.70s) --- PASS: TestAccAWSS3BucketInventory_basic (26.73s) --- PASS: TestAccAWSS3BucketInventory_encryptWithSSES3 (27.01s) ```
1 parent d18d9c0 commit e6cc362

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

aws/resource_aws_s3_bucket_inventory.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,21 +200,21 @@ func resourceAwsS3BucketInventoryPut(d *schema.ResourceData, meta interface{}) e
200200
inventoryConfiguration.OptionalFields = expandStringList(v.(*schema.Set).List())
201201
}
202202

203-
if v, ok := d.GetOk("schedule"); ok {
203+
if v, ok := d.GetOk("schedule"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {
204204
scheduleList := v.([]interface{})
205205
scheduleMap := scheduleList[0].(map[string]interface{})
206206
inventoryConfiguration.Schedule = &s3.InventorySchedule{
207207
Frequency: aws.String(scheduleMap["frequency"].(string)),
208208
}
209209
}
210210

211-
if v, ok := d.GetOk("filter"); ok {
211+
if v, ok := d.GetOk("filter"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {
212212
filterList := v.([]interface{})
213213
filterMap := filterList[0].(map[string]interface{})
214214
inventoryConfiguration.Filter = expandS3InventoryFilter(filterMap)
215215
}
216216

217-
if v, ok := d.GetOk("destination"); ok {
217+
if v, ok := d.GetOk("destination"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {
218218
destinationList := v.([]interface{})
219219
destinationMap := destinationList[0].(map[string]interface{})
220220
bucketList := destinationMap["bucket"].([]interface{})

0 commit comments

Comments
 (0)