Skip to content

Commit

Permalink
resource/aws_s3_bucket_inventory: Prevent crashes with empty destinat…
Browse files Browse the repository at this point in the history
…ion, 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)
```
  • Loading branch information
bflad committed Jan 12, 2021
1 parent d18d9c0 commit e6cc362
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions aws/resource_aws_s3_bucket_inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,21 +200,21 @@ func resourceAwsS3BucketInventoryPut(d *schema.ResourceData, meta interface{}) e
inventoryConfiguration.OptionalFields = expandStringList(v.(*schema.Set).List())
}

if v, ok := d.GetOk("schedule"); ok {
if v, ok := d.GetOk("schedule"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {
scheduleList := v.([]interface{})
scheduleMap := scheduleList[0].(map[string]interface{})
inventoryConfiguration.Schedule = &s3.InventorySchedule{
Frequency: aws.String(scheduleMap["frequency"].(string)),
}
}

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

if v, ok := d.GetOk("destination"); ok {
if v, ok := d.GetOk("destination"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {
destinationList := v.([]interface{})
destinationMap := destinationList[0].(map[string]interface{})
bucketList := destinationMap["bucket"].([]interface{})
Expand Down

0 comments on commit e6cc362

Please sign in to comment.