Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor S3 Bucket Metric resource to use keyvaluetags package. #11963

Merged
merged 1 commit into from
Feb 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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