Skip to content

Commit fd634b9

Browse files
authored
Merge pull request #14230 from terraform-providers/b-s3-bucket-mtric-filter
resource/s3_bucket_metric: add atleastoneof property to filter attributes
2 parents 029fe81 + eff1528 commit fd634b9

4 files changed

Lines changed: 40 additions & 3 deletions

File tree

aws/resource_aws_s3_bucket_metric.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,16 @@ func resourceAwsS3BucketMetric() *schema.Resource {
3636
Elem: &schema.Resource{
3737
Schema: map[string]*schema.Schema{
3838
"prefix": {
39-
Type: schema.TypeString,
40-
Optional: true,
39+
Type: schema.TypeString,
40+
Optional: true,
41+
AtLeastOneOf: filterAtLeastOneOfKeys,
42+
},
43+
"tags": {
44+
Type: schema.TypeMap,
45+
Optional: true,
46+
Elem: &schema.Schema{Type: schema.TypeString},
47+
AtLeastOneOf: filterAtLeastOneOfKeys,
4148
},
42-
"tags": tagsSchema(),
4349
},
4450
},
4551
},

aws/resource_aws_s3_bucket_metric_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"log"
66
"reflect"
7+
"regexp"
78
"sort"
89
"testing"
910
"time"
@@ -292,6 +293,8 @@ func TestAccAWSS3BucketMetric_basic(t *testing.T) {
292293
})
293294
}
294295

296+
// Reference: https://github.com/terraform-providers/terraform-provider-aws/issues/11813
297+
// Disallow Empty filter block
295298
func TestAccAWSS3BucketMetric_WithEmptyFilter(t *testing.T) {
296299
var conf s3.MetricsConfiguration
297300
rInt := acctest.RandInt()
@@ -310,6 +313,7 @@ func TestAccAWSS3BucketMetric_WithEmptyFilter(t *testing.T) {
310313
Check: resource.ComposeTestCheckFunc(
311314
testAccCheckAWSS3BucketMetricsConfigExists(resourceName, &conf),
312315
),
316+
ExpectError: regexp.MustCompile(`config is invalid`),
313317
},
314318
},
315319
})

website/docs/guides/version-3-upgrade.html.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Upgrade topics:
3434
- [Resource: aws_msk_cluster](#resource-aws_msk_cluster)
3535
- [Resource: aws_rds_cluster](#resource-aws_rds_cluster)
3636
- [Resource: aws_s3_bucket](#resource-aws_s3_bucket)
37+
- [Resource: aws_s3_bucket_metric](#resource-aws_s3_bucket_metric)
3738
- [Resource: aws_security_group](#resource-aws_security_group)
3839
- [Resource: aws_sns_platform_application](#resource-aws_sns_platform_application)
3940
- [Resource: aws_spot_fleet_request](#resource-aws_spot_fleet_request)
@@ -517,6 +518,30 @@ resource "aws_s3_bucket" "example" {
517518
}
518519
```
519520

521+
## Resource: aws_s3_bucket_metric
522+
523+
### filter configuration block Plan-Time Validation Change
524+
525+
The `filter` configuration block no longer supports the empty block `{}` and requires at least one of the `prefix` or `tags` attributes to be specified.
526+
527+
For example, given this previous configuration:
528+
529+
```hcl
530+
resource "aws_s3_bucket_metric" "example" {
531+
# ... other configuration ...
532+
533+
filter {}
534+
}
535+
```
536+
537+
An updated configuration:
538+
539+
```hcl
540+
resource "aws_s3_bucket_metric" "example" {
541+
# ... other configuration ...
542+
}
543+
```
544+
520545
## Resource: aws_security_group
521546

522547
### Removal of Automatic aws_security_group_rule Import

website/docs/r/s3_bucket_metric.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ The following arguments are supported:
5757

5858
The `filter` metric configuration supports the following:
5959

60+
~> **NOTE**: At least one of `prefix` or `tags` is required when specifying a `filter`
61+
6062
* `prefix` - (Optional) Object prefix for filtering (singular).
6163
* `tags` - (Optional) Object tags for filtering (up to 10).
6264

0 commit comments

Comments
 (0)