Skip to content

Commit

Permalink
default to empty list
Browse files Browse the repository at this point in the history
  • Loading branch information
mscoutermarsh committed Jan 31, 2025
1 parent 6fc44af commit 0d623a1
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions internal/provider/password_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"strings"

"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
Expand Down Expand Up @@ -71,6 +72,12 @@ func passwordResourceFromClient(ctx context.Context, password *planetscale.Passw
diags.Append(diags...)
region, diags := types.ObjectValueFrom(ctx, regionResourceAttrTypes, password.Region)
diags.Append(diags...)

cidrs := types.ListValueMust(types.StringType, []attr.Value{})
if password.Cidrs != nil {
cidrs = stringsToListValue(password.Cidrs, diags)
}

return &passwordResourceModel{
Organization: organization,
Database: database,
Expand All @@ -89,7 +96,7 @@ func passwordResourceFromClient(ctx context.Context, password *planetscale.Passw
Role: types.StringValue(password.Role),
TtlSeconds: types.Float64Value(password.TtlSeconds),
Username: types.StringPointerValue(password.Username),
Cidrs: stringsToListValue(password.Cidrs, diags),
Cidrs: cidrs,
PlainText: plainText,

// manually removed from spec because currently buggy
Expand All @@ -107,6 +114,12 @@ func passwordWithPlaintextResourceFromClient(ctx context.Context, password *plan
diags.Append(diags...)
region, diags := types.ObjectValueFrom(ctx, regionResourceAttrTypes, password.Region)
diags.Append(diags...)

cidrs := types.ListValueMust(types.StringType, []attr.Value{})
if password.Cidrs != nil {
cidrs = stringsToListValue(password.Cidrs, diags)
}

return &passwordResourceModel{
Organization: organization,
Database: database,
Expand All @@ -125,7 +138,7 @@ func passwordWithPlaintextResourceFromClient(ctx context.Context, password *plan
Role: types.StringValue(password.Role),
TtlSeconds: types.Float64Value(password.TtlSeconds),
Username: types.StringPointerValue(password.Username),
Cidrs: stringsToListValue(password.Cidrs, diags),
Cidrs: cidrs,
PlainText: types.StringValue(password.PlainText),

// manually removed from spec because currently buggy
Expand Down Expand Up @@ -188,7 +201,6 @@ func (r *passwordResource) Schema(ctx context.Context, req resource.SchemaReques
"cidrs": schema.ListAttribute{
Description: "List of IP addresses or CIDR ranges that can use this password.",
Optional: true,
Computed: false,
ElementType: types.StringType,
},

Expand Down

0 comments on commit 0d623a1

Please sign in to comment.