Skip to content

Commit

Permalink
Merge pull request #11963 from ewbankkit/s3-metrics-keyvaluetags
Browse files Browse the repository at this point in the history
Refactor S3 Bucket Metric resource to use keyvaluetags package.
  • Loading branch information
gdavison authored Feb 10, 2020
2 parents 67e501b + 93ebae8 commit 160c3bc
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions aws/resource_aws_s3_bucket_metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/aws/aws-sdk-go/service/s3"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags"
)

func resourceAwsS3BucketMetric() *schema.Resource {
Expand Down Expand Up @@ -165,7 +166,7 @@ func expandS3MetricsFilter(m map[string]interface{}) *s3.MetricsFilter {

var tags []*s3.Tag
if v, ok := m["tags"]; ok {
tags = tagsFromMapS3(v.(map[string]interface{}))
tags = keyvaluetags.New(v).IgnoreAws().S3Tags()
}

metricsFilter := &s3.MetricsFilter{}
Expand Down Expand Up @@ -195,15 +196,15 @@ func flattenS3MetricsFilter(metricsFilter *s3.MetricsFilter) map[string]interfac
m["prefix"] = *and.Prefix
}
if and.Tags != nil {
m["tags"] = tagsToMapS3(and.Tags)
m["tags"] = keyvaluetags.S3KeyValueTags(and.Tags).IgnoreAws().Map()
}
} else if metricsFilter.Prefix != nil {
m["prefix"] = *metricsFilter.Prefix
} else if metricsFilter.Tag != nil {
tags := []*s3.Tag{
metricsFilter.Tag,
}
m["tags"] = tagsToMapS3(tags)
m["tags"] = keyvaluetags.S3KeyValueTags(tags).IgnoreAws().Map()
}
return m
}
Expand Down

0 comments on commit 160c3bc

Please sign in to comment.