diff --git a/aws/resource_aws_s3_bucket_metric.go b/aws/resource_aws_s3_bucket_metric.go index c67f56b7434..a02008a5419 100644 --- a/aws/resource_aws_s3_bucket_metric.go +++ b/aws/resource_aws_s3_bucket_metric.go @@ -62,8 +62,9 @@ func resourceAwsS3BucketMetricPut(d *schema.ResourceData, meta interface{}) erro if v, ok := d.GetOk("filter"); ok { filterList := v.([]interface{}) - filterMap := filterList[0].(map[string]interface{}) - metricsConfiguration.Filter = expandS3MetricsFilter(filterMap) + if filterMap, ok := filterList[0].(map[string]interface{}); ok { + metricsConfiguration.Filter = expandS3MetricsFilter(filterMap) + } } input := &s3.PutBucketMetricsConfigurationInput{ diff --git a/aws/resource_aws_s3_bucket_metric_test.go b/aws/resource_aws_s3_bucket_metric_test.go index 0be126df970..8057089b640 100644 --- a/aws/resource_aws_s3_bucket_metric_test.go +++ b/aws/resource_aws_s3_bucket_metric_test.go @@ -292,6 +292,29 @@ func TestAccAWSS3BucketMetric_basic(t *testing.T) { }) } +func TestAccAWSS3BucketMetric_WithEmptyFilter(t *testing.T) { + var conf s3.MetricsConfiguration + rInt := acctest.RandInt() + resourceName := "aws_s3_bucket_metric.test" + + bucketName := fmt.Sprintf("tf-acc-%d", rInt) + metricName := t.Name() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSS3BucketMetricDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSS3BucketMetricsConfigWithEmptyFilter(bucketName, metricName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSS3BucketMetricsConfigExists(resourceName, &conf), + ), + }, + }, + }) +} + func TestAccAWSS3BucketMetric_WithFilterPrefix(t *testing.T) { var conf s3.MetricsConfiguration rInt := acctest.RandInt() @@ -604,6 +627,18 @@ resource "aws_s3_bucket" "bucket" { `, name) } +func testAccAWSS3BucketMetricsConfigWithEmptyFilter(bucketName, metricName string) string { + return fmt.Sprintf(` +%s + +resource "aws_s3_bucket_metric" "test" { + bucket = "${aws_s3_bucket.bucket.id}" + name = "%s" + filter {} +} +`, testAccAWSS3BucketMetricsConfigBucket(bucketName), metricName) +} + func testAccAWSS3BucketMetricsConfigWithFilterPrefix(bucketName, metricName, prefix string) string { return fmt.Sprintf(` %s