Skip to content

Commit 42b497f

Browse files
author
protobuf-ci-cd
committed
use regionial ID
1 parent 8aa786c commit 42b497f

File tree

2 files changed

+3
-10
lines changed

2 files changed

+3
-10
lines changed

internal/services/keymanager/helpers.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ func UsageToString(u *key_manager.KeyUsage) string {
3232
return ""
3333
}
3434

35-
// ExtractRegionAndKeyID parses an ID of the form "region/key_id" and returns the region and key ID.
3635
func ExtractRegionAndKeyID(id string) (scw.Region, string, error) {
3736
parts := strings.SplitN(id, "/", 2)
3837
if len(parts) != 2 {
@@ -53,7 +52,6 @@ func newKeyManagerAPI(d *schema.ResourceData, m any) (*key_manager.API, scw.Regi
5352
return api, region, nil
5453
}
5554

56-
// NewKeyManagerAPIWithRegionAndID returns a Key Manager API client, region, and key ID from meta and a composite ID.
5755
func NewKeyManagerAPIWithRegionAndID(m any, id string) (*key_manager.API, scw.Region, string, error) {
5856
region, keyID, err := ExtractRegionAndKeyID(id)
5957
if err != nil {
@@ -65,9 +63,7 @@ func NewKeyManagerAPIWithRegionAndID(m any, id string) (*key_manager.API, scw.Re
6563
return client, region, keyID, nil
6664
}
6765

68-
// ExpandKeyUsage converts a usage string to a *key_manager.KeyUsage struct for API requests.
6966
func ExpandKeyUsage(usage string) *key_manager.KeyUsage {
70-
// You can extend this switch if you want to support more algorithms in the future
7167
switch usage {
7268
case "symmetric_encryption":
7369
alg := key_manager.KeyAlgorithmSymmetricEncryptionAes256Gcm
@@ -86,7 +82,6 @@ func ExpandKeyUsage(usage string) *key_manager.KeyUsage {
8682
}
8783
}
8884

89-
// ExpandKeyRotationPolicy converts a Terraform rotation_policy value to a *key_manager.KeyRotationPolicy.
9085
func ExpandKeyRotationPolicy(v any) (*key_manager.KeyRotationPolicy, error) {
9186
list, ok := v.([]any)
9287
if !ok || len(list) == 0 {
@@ -113,7 +108,6 @@ func ExpandKeyRotationPolicy(v any) (*key_manager.KeyRotationPolicy, error) {
113108
}, nil
114109
}
115110

116-
// FlattenKeyRotationPolicy converts a *key_manager.KeyRotationPolicy to a []map[string]any for Terraform.
117111
func FlattenKeyRotationPolicy(rp *key_manager.KeyRotationPolicy) []map[string]any {
118112
if rp == nil {
119113
return nil

internal/services/keymanager/key_resource.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package keymanager
22

33
import (
44
"context"
5-
"fmt"
65

76
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
87
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -25,8 +24,8 @@ func ResourceKeyManagerKey() *schema.Resource {
2524
Optional: true,
2625
Description: "Name of the key.",
2726
},
28-
"project_id": account.ProjectIDSchema(), // ID of the Project containing the key.
29-
"region": regional.Schema(), // Region where the key is stored.
27+
"project_id": account.ProjectIDSchema(),
28+
"region": regional.Schema(),
3029
"usage": {
3130
Type: schema.TypeString,
3231
Required: true,
@@ -123,7 +122,7 @@ func resourceKeyManagerKeyCreate(ctx context.Context, d *schema.ResourceData, m
123122
return diag.FromErr(err)
124123
}
125124

126-
d.SetId(fmt.Sprintf("%s/%s", key.Region, key.ID))
125+
d.SetId(regional.NewIDString(key.Region, key.ID))
127126

128127
return resourceKeyManagerKeyRead(ctx, d, m)
129128
}

0 commit comments

Comments
 (0)