Skip to content

Commit cbd2561

Browse files
author
protobuf-ci-cd
committed
use types helpers
1 parent a1d71b6 commit cbd2561

File tree

2 files changed

+7
-30
lines changed

2 files changed

+7
-30
lines changed

internal/services/keymanager/helpers.go

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,12 @@ package keymanager
33
import (
44
"fmt"
55
"strings"
6-
"time"
76

87
key_manager "github.com/scaleway/scaleway-sdk-go/api/key_manager/v1alpha1"
98
"github.com/scaleway/scaleway-sdk-go/scw"
109
"github.com/scaleway/terraform-provider-scaleway/v2/internal/meta"
1110
)
1211

13-
func ExpandStringList(v any) []string {
14-
var result []string
15-
16-
list := v.([]any)
17-
18-
for i, s := range list {
19-
_ = i
20-
21-
if str, ok := s.(string); ok {
22-
result = append(result, str)
23-
}
24-
}
25-
26-
return result
27-
}
2812

2913
func UsageToString(u *key_manager.KeyUsage) string {
3014
if u == nil {
@@ -46,14 +30,6 @@ func UsageToString(u *key_manager.KeyUsage) string {
4630
return ""
4731
}
4832

49-
func TimeToRFC3339(t *time.Time) string {
50-
if t == nil {
51-
return ""
52-
}
53-
54-
return t.Format(time.RFC3339)
55-
}
56-
5733
// ExtractRegionAndKeyID parses an ID of the form "region/key_id" and returns the region and key ID.
5834
func ExtractRegionAndKeyID(id string) (scw.Region, string, error) {
5935
parts := strings.SplitN(id, "/", 2)

internal/services/keymanager/key_resource.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/regional"
1414
"github.com/scaleway/terraform-provider-scaleway/v2/internal/meta"
1515
"github.com/scaleway/terraform-provider-scaleway/v2/internal/services/account"
16+
"github.com/scaleway/terraform-provider-scaleway/v2/internal/types"
1617
)
1718

1819
func ResourceKeyManagerKey() *schema.Resource {
@@ -92,7 +93,7 @@ func resourceKeyManagerKeyCreate(ctx context.Context, d *schema.ResourceData, m
9293
description := d.Get("description").(string)
9394
unprotected := d.Get("unprotected").(bool)
9495
origin := d.Get("origin").(string)
95-
tags := ExpandStringList(d.Get("tags"))
96+
tags := types.ExpandStrings(d.Get("tags"))
9697

9798
var usageBlock *key_manager.KeyUsage
9899

@@ -171,11 +172,11 @@ func resourceKeyManagerKeyRead(ctx context.Context, d *schema.ResourceData, m an
171172
_ = d.Set("description", key.Description)
172173
_ = d.Set("tags", key.Tags)
173174
_ = d.Set("rotation_count", int(key.RotationCount))
174-
_ = d.Set("created_at", TimeToRFC3339(key.CreatedAt))
175-
_ = d.Set("updated_at", TimeToRFC3339(key.UpdatedAt))
175+
_ = d.Set("created_at", types.FlattenTime(key.CreatedAt))
176+
_ = d.Set("updated_at", types.FlattenTime(key.UpdatedAt))
176177
_ = d.Set("protected", key.Protected)
177178
_ = d.Set("locked", key.Locked)
178-
_ = d.Set("rotated_at", TimeToRFC3339(key.RotatedAt))
179+
_ = d.Set("rotated_at", types.FlattenTime(key.RotatedAt))
179180
_ = d.Set("origin_read", key.Origin.String())
180181
_ = d.Set("region_read", key.Region.String())
181182

@@ -189,7 +190,7 @@ func resourceKeyManagerKeyRead(ctx context.Context, d *schema.ResourceData, m an
189190
_ = d.Set("rotation_policy", []map[string]any{
190191
{
191192
"rotation_period": periodStr,
192-
"next_rotation_at": TimeToRFC3339(key.RotationPolicy.NextRotationAt),
193+
"next_rotation_at": types.FlattenTime(key.RotationPolicy.NextRotationAt),
193194
},
194195
})
195196
}
@@ -219,7 +220,7 @@ func resourceKeyManagerKeyUpdate(ctx context.Context, d *schema.ResourceData, m
219220
}
220221

221222
if d.HasChange("tags") {
222-
tags := ExpandStringList(d.Get("tags"))
223+
tags := types.ExpandStrings(d.Get("tags"))
223224
updateReq.Tags = &tags
224225
}
225226

0 commit comments

Comments
 (0)