Skip to content

Commit e9d2c31

Browse files
committed
fix review
Signed-off-by: Patrik Cyvoct <[email protected]>
1 parent 5448484 commit e9d2c31

File tree

3 files changed

+41
-33
lines changed

3 files changed

+41
-33
lines changed

scaleway/helpers_object.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package scaleway
2+
3+
import (
4+
"github.com/aws/aws-sdk-go/service/s3"
5+
"github.com/scaleway/scaleway-sdk-go/scw"
6+
)
7+
8+
func flattenObjectBucketTags(tagsSet []*s3.Tag) map[string]interface{} {
9+
tags := map[string]interface{}{}
10+
11+
for _, tagSet := range tagsSet {
12+
var key string
13+
var value string
14+
if tagSet.Key != nil {
15+
key = *tagSet.Key
16+
}
17+
if tagSet.Value != nil {
18+
value = *tagSet.Value
19+
}
20+
tags[key] = value
21+
}
22+
23+
return tags
24+
}
25+
26+
func expandObjectBucketTags(tags interface{}) []*s3.Tag {
27+
tagsSet := make([]*s3.Tag, 0)
28+
29+
for key, value := range tags.(map[string]interface{}) {
30+
tagsSet = append(tagsSet, &s3.Tag{
31+
Key: &key,
32+
Value: scw.StringPtr(value.(string)),
33+
})
34+
}
35+
36+
return tagsSet
37+
}

scaleway/resource_object_bucket.go

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"github.com/aws/aws-sdk-go/service/s3"
99
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
1010
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
11-
"github.com/scaleway/scaleway-sdk-go/scw"
1211
)
1312

1413
func resourceScalewayObjectBucket() *schema.Resource {
@@ -69,14 +68,7 @@ func resourceScalewayObjectBucketCreate(d *schema.ResourceData, m interface{}) e
6968
return err
7069
}
7170

72-
tagsSet := make([]*s3.Tag, 0)
73-
74-
for key, value := range d.Get("tags").(map[string]interface{}) {
75-
tagsSet = append(tagsSet, &s3.Tag{
76-
Key: &key,
77-
Value: scw.StringPtr(value.(string)),
78-
})
79-
}
71+
tagsSet := expandObjectBucketTags(d.Get("tags"))
8072

8173
if len(tagsSet) > 0 {
8274
_, err = s3Client.PutBucketTagging(&s3.PutBucketTaggingInput{
@@ -137,21 +129,7 @@ func resourceScalewayObjectBucketRead(d *schema.ResourceData, m interface{}) err
137129
tagsSet = tagsResponse.TagSet
138130
}
139131

140-
tags := map[string]interface{}{}
141-
142-
for _, tagSet := range tagsSet {
143-
var key string
144-
var value string
145-
if tagSet.Key != nil {
146-
key = *tagSet.Key
147-
}
148-
if tagSet.Value != nil {
149-
value = *tagSet.Value
150-
}
151-
tags[key] = value
152-
}
153-
154-
_ = d.Set("tags", tags)
132+
_ = d.Set("tags", flattenObjectBucketTags(tagsSet))
155133

156134
return nil
157135
}
@@ -176,14 +154,7 @@ func resourceScalewayObjectBucketUpdate(d *schema.ResourceData, m interface{}) e
176154
}
177155

178156
if d.HasChange("tags") {
179-
tagsSet := make([]*s3.Tag, 0)
180-
181-
for key, value := range d.Get("tags").(map[string]interface{}) {
182-
tagsSet = append(tagsSet, &s3.Tag{
183-
Key: &key,
184-
Value: scw.StringPtr(value.(string)),
185-
})
186-
}
157+
tagsSet := expandObjectBucketTags(d.Get("tags"))
187158

188159
_, err = s3Client.PutBucketTagging(&s3.PutBucketTaggingInput{
189160
Bucket: aws.String(bucketName),

website/docs/r/object_bucket.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ resource "scaleway_object_bucket" "some_bucket" {
2626
The following arguments are supported:
2727

2828
* `name` - (Required) The name of the bucket.
29-
* `tags` - (Optional) The tags of the bucket.
29+
* `tags` - (Optional) A list of tags (key / value) for the bucket.
3030
* `acl` - (Optional) The [canned ACL](https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl) you want to apply to the bucket.
3131
* `region` - (Optional) The [region](https://developers.scaleway.com/en/quickstart/#region-definition) in which the bucket should be created.
3232

0 commit comments

Comments
 (0)