Skip to content

Commit

Permalink
update resource schema to match latest api
Browse files Browse the repository at this point in the history
  • Loading branch information
joemiller committed Oct 5, 2024
1 parent a0184a0 commit 0e8da50
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 29 deletions.
17 changes: 7 additions & 10 deletions internal/provider/database_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,11 @@ func databaseResourcefromClient(ctx context.Context, database *planetscale.Datab
dataImport, diags := types.ObjectValueFrom(ctx, importResourceAttrTypes, database.DataImport)
diags.Append(diags...)
return &databaseResourceModel{
Organization: organization,
DataImport: dataImport,
Id: types.StringValue(database.Id),
AllowDataBranching: types.BoolValue(database.AllowDataBranching),
AtBackupRestoreBranchesLimit: types.BoolValue(database.AtBackupRestoreBranchesLimit),
// AtDevelopmentBranchLimit: types.BoolValue(database.AtDevelopmentBranchLimit),
Organization: organization,
DataImport: dataImport,
Id: types.StringValue(database.Id),
AllowDataBranching: types.BoolValue(database.AllowDataBranching),
AtBackupRestoreBranchesLimit: types.BoolValue(database.AtBackupRestoreBranchesLimit),
AtDevelopmentBranchLimit: types.BoolValue(false), // at_development_branch_limit removed from API, hardcode to false going forward
AutomaticMigrations: types.BoolPointerValue(database.AutomaticMigrations),
BranchesCount: types.Float64Value(database.BranchesCount),
Expand Down Expand Up @@ -364,11 +363,9 @@ func (r *databaseResource) Create(ctx context.Context, req resource.CreateReques
}

createDbReq := planetscale.CreateDatabaseReq{
Name: name.ValueString(),
// Plan: stringValueIfKnown(data.Plan),
Name: name.ValueString(),
ClusterSize: data.ClusterSize.ValueString(),
// ClusterSize: float64ValueIfKnown(data.ClusterSize),
Region: stringValueIfKnown(data.Region),
Region: stringValueIfKnown(data.Region),
}
res, err := r.client.CreateDatabase(ctx, org.ValueString(), createDbReq)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion internal/provider/password_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ func (d *passwordDataSource) Read(ctx context.Context, req datasource.ReadReques
data.Database.ValueString(),
data.Branch.ValueString(),
data.Id.ValueString(),
// data.ReadOnlyRegionId.ValueStringPointer(),
)
if err != nil {
resp.Diagnostics.AddError("Unable to read database password", err.Error())
Expand Down
1 change: 0 additions & 1 deletion internal/provider/password_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,6 @@ func (r *passwordResource) Read(ctx context.Context, req resource.ReadRequest, r
database.ValueString(),
branch.ValueString(),
id.ValueString(),
// nil, // not sure why this would need a region id
)
if err != nil {
if notFoundErr, ok := err.(*planetscale.GetPasswordRes404); ok {
Expand Down
56 changes: 39 additions & 17 deletions internal/provider/user_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ type userDataSource struct {
}

type userDataSourceModel struct {
Id *string `tfsdk:"id"`
Name *string `tfsdk:"name"`
AvatarUrl *string `tfsdk:"avatar_url"`
CreatedAt *string `tfsdk:"created_at"`
DefaultOrganizationId *string `tfsdk:"default_organization_id"`
DirectoryManaged *bool `tfsdk:"directory_managed"`
DisplayName *string `tfsdk:"display_name"`
Email *string `tfsdk:"email"`
EmailVerified *bool `tfsdk:"email_verified"`
Managed *bool `tfsdk:"managed"`
Sso *bool `tfsdk:"sso"`
TwoFactorAuthConfigured *bool `tfsdk:"two_factor_auth_configured"`
UpdatedAt *string `tfsdk:"updated_at"`
Id *string `tfsdk:"id"`
Name *string `tfsdk:"name"`
AvatarUrl *string `tfsdk:"avatar_url"`
CreatedAt *string `tfsdk:"created_at"`
DefaultOrganization *planetscale.User_DefaultOrganization `tfsdk:"default_organization"`
DirectoryManaged *bool `tfsdk:"directory_managed"`
DisplayName *string `tfsdk:"display_name"`
Email *string `tfsdk:"email"`
EmailVerified *bool `tfsdk:"email_verified"`
Managed *bool `tfsdk:"managed"`
Sso *bool `tfsdk:"sso"`
TwoFactorAuthConfigured *bool `tfsdk:"two_factor_auth_configured"`
UpdatedAt *string `tfsdk:"updated_at"`
}

func (d *userDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
Expand Down Expand Up @@ -66,9 +66,31 @@ Known limitations:
Description: "When the user was created.",
Computed: true,
},
"default_organization_id": schema.StringAttribute{
"default_organization": schema.SingleNestedAttribute{
Description: "The default organization for the user.",
Computed: true,
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Description: "The ID of the organization.",
Computed: true,
},
"name": schema.StringAttribute{
Description: "The name of the organization.",
Computed: true,
},
"created_at": schema.StringAttribute{
Description: "When the organization was created.",
Computed: true,
},
"updated_at": schema.StringAttribute{
Description: "When the organization was last updated.",
Computed: true,
},
"deleted_at": schema.StringAttribute{
Description: "When the organization was last deleted.",
Computed: true,
},
},
},
"directory_managed": schema.BoolAttribute{
Description: "Whether or not the user is managed by a WorkOS directory.",
Expand Down Expand Up @@ -137,10 +159,10 @@ func (d *userDataSource) Read(ctx context.Context, req datasource.ReadRequest, r
return
}
state := userDataSourceModel{
AvatarUrl: res200.AvatarUrl,
CreatedAt: res200.CreatedAt,
// DefaultOrganizationId: res200.DefaultOrganizationId,
AvatarUrl: res200.AvatarUrl,
CreatedAt: res200.CreatedAt,
DirectoryManaged: res200.DirectoryManaged,
DefaultOrganization: &res200.DefaultOrganization,
DisplayName: res200.DisplayName,
Email: res200.Email,
EmailVerified: res200.EmailVerified,
Expand Down

0 comments on commit 0e8da50

Please sign in to comment.