Skip to content

Commit 9e85497

Browse files
committed
chore: fixed import example
chore: generic NullableToString. Handles enum as well
1 parent 722fe8f commit 9e85497

File tree

4 files changed

+7
-18
lines changed

4 files changed

+7
-18
lines changed

docs/resources/apikey.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ Import is supported using the following syntax:
5252
The [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import) can be used, for example:
5353

5454
```shell
55-
# Apikey can be imported by specifying the <project_ref>/<apikey_uuid> identifier.
56-
terraform import hashicups_order.example mayuaycdtijbctgqbycg/601f6916-62a3-428b-9ebf-a433c7cac8b7
55+
# The ID is the project reference and a unique identifier of the key separated by '/'
56+
terraform import supabase_apikey.example <project_ref>/<key_id>
5757
```
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
# Apikey can be imported by specifying the <project_ref>/<apikey_uuid> identifier.
2-
terraform import hashicups_order.example mayuaycdtijbctgqbycg/601f6916-62a3-428b-9ebf-a433c7cac8b7
1+
# The ID is the project reference and a unique identifier of the key separated by '/'
2+
terraform import supabase_apikey.example <project_ref>/<key_id>

internal/provider/apikey_resource.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ func readApiKeyDatabase(ctx context.Context, state *ApiKeyResourceModel, client
254254

255255
idValue := NullableToString(httpResp.JSON200.Id)
256256
apiKeyValue := NullableToString(httpResp.JSON200.ApiKey)
257-
typeValue := NullableEnumToString(httpResp.JSON200.Type)
257+
typeValue := NullableToString(httpResp.JSON200.Type)
258258
descriptionValue := NullableToString(httpResp.JSON200.Description)
259259

260260
database := ApiKeyDatabaseModel{
@@ -360,7 +360,7 @@ func createApiKey(ctx context.Context, plan *ApiKeyResourceModel, client *api.Cl
360360
// Update computed fields from creation response
361361
plan.Id = NullableToString(httpResp.JSON201.Id)
362362
plan.ApiKey = NullableToString(httpResp.JSON201.ApiKey)
363-
plan.Type = NullableEnumToString(httpResp.JSON201.Type)
363+
plan.Type = NullableToString(httpResp.JSON201.Type)
364364

365365
obj, diags := types.ObjectValue(secretJwtTemplateAttrTypes, map[string]attr.Value{
366366
"role": types.StringValue("service_role"),

internal/provider/utils.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,7 @@ func Ptr[T any](v T) *T {
1111

1212
// NullableToString converts an oapi-codegen [nullable.Nullable] to an appropriate
1313
// terraform string type.
14-
func NullableToString(n nullable.Nullable[string]) tftypes.String {
15-
if n.IsSpecified() && !n.IsNull() {
16-
// MustGet is safe when the value is specified and not null
17-
return tftypes.StringValue(n.MustGet())
18-
}
19-
20-
return tftypes.StringNull()
21-
}
22-
23-
// NullableEnumToString converts an oapi-codegen nullable enum (or any string-like
24-
// type) into a terraform string type.
25-
func NullableEnumToString[T ~string](n nullable.Nullable[T]) tftypes.String {
14+
func NullableToString[T ~string](n nullable.Nullable[T]) tftypes.String {
2615
if n.IsSpecified() && !n.IsNull() {
2716
return tftypes.StringValue(string(n.MustGet()))
2817
}

0 commit comments

Comments
 (0)