chore: adjust pagination for postgres database and flavor listing (#20)
* feat: implement pagination for database listing * fix: change database_id attribute type from string to int64 * refactor: rename getDatabase to getDatabaseById for clarity * fix: improve error handling for database not found scenario * feat: add validation for database_id and name attributes; implement separate functions for fetching databases by ID and name * feat: implement database client interface and update database fetching functions * refactor: rename matcher to filter for clarity and update pagination logic * feat: implement flavors retrieval with pagination and filtering support * refactor: rename flavor import for consistency and clarity * feat: add support for InstanceStatePending in wait handler logic * refactor: simplify GetFlavorsRequest and GetFlavorsRequestExecute by removing pagination parameters * refactor: improve readability of test cases by formatting function signatures and restructuring test runs * refactor: remove pagination parameters from GetFlavorsRequest in test case * refactor: simplify function signatures and improve readability in datasource and resource files * refactor: add descriptions for user-related attributes in datasource schema * refactor: enhance user resource schema with additional attributes and improve logging * refactor: delete unused file * refactor: standardize formatting and improve function naming for user resource management * refactor: remove skip from TestMapFields and update roles initialization in resource tests * fix: golangci lint issues * fix: golangci lint issues again * fix: golangci lint issues again
This commit is contained in:
parent
0150fea302
commit
979220be66
26 changed files with 3630 additions and 2759 deletions
|
|
@ -259,7 +259,7 @@ func (r *databaseResource) Create(
|
|||
databaseId := *databaseResp.Id
|
||||
ctx = tflog.SetField(ctx, "database_id", databaseId)
|
||||
|
||||
database, err := getDatabase(ctx, r.client, projectId, region, instanceId, databaseId)
|
||||
database, err := getDatabaseById(ctx, r.client, projectId, region, instanceId, databaseId)
|
||||
if err != nil {
|
||||
core.LogAndAddError(
|
||||
ctx,
|
||||
|
|
@ -314,7 +314,7 @@ func (r *databaseResource) Read(
|
|||
ctx = tflog.SetField(ctx, "database_id", databaseId)
|
||||
ctx = tflog.SetField(ctx, "region", region)
|
||||
|
||||
databaseResp, err := getDatabase(ctx, r.client, projectId, region, instanceId, databaseId)
|
||||
databaseResp, err := getDatabaseById(ctx, r.client, projectId, region, instanceId, databaseId)
|
||||
if err != nil {
|
||||
oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
|
||||
if (ok && oapiErr.StatusCode == http.StatusNotFound) || errors.Is(err, errDatabaseNotFound) {
|
||||
|
|
@ -353,7 +353,7 @@ func (r *databaseResource) Update(
|
|||
ctx context.Context,
|
||||
req resource.UpdateRequest,
|
||||
resp *resource.UpdateResponse,
|
||||
) { // nolint:gocritic // function signature required by Terraform
|
||||
) {
|
||||
var model Model
|
||||
diags := req.Plan.Get(ctx, &model)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
|
|
@ -430,7 +430,6 @@ func (r *databaseResource) Update(
|
|||
return
|
||||
}
|
||||
tflog.Info(ctx, "Postgres Flex database updated")
|
||||
|
||||
}
|
||||
|
||||
// Delete deletes the resource and removes the Terraform state on success.
|
||||
|
|
@ -530,14 +529,11 @@ func mapFields(resp *postgresflexalpha.ListDatabase, model *Model, region string
|
|||
return nil
|
||||
}
|
||||
|
||||
func mapFieldsUpdate(res *postgresflexalpha.UpdateDatabaseResponse, model *Model, region string) error {
|
||||
if res == nil {
|
||||
return fmt.Errorf("response is nil")
|
||||
}
|
||||
return mapFields(res.Database, model, region)
|
||||
}
|
||||
|
||||
func mapFieldsUpdatePartially(res *postgresflexalpha.UpdateDatabasePartiallyResponse, model *Model, region string) error {
|
||||
func mapFieldsUpdatePartially(
|
||||
res *postgresflexalpha.UpdateDatabasePartiallyResponse,
|
||||
model *Model,
|
||||
region string,
|
||||
) error {
|
||||
if res == nil {
|
||||
return fmt.Errorf("response is nil")
|
||||
}
|
||||
|
|
@ -564,26 +560,3 @@ func toCreatePayload(model *Model) (*postgresflexalpha.CreateDatabaseRequestPayl
|
|||
}
|
||||
|
||||
var errDatabaseNotFound = errors.New("database not found")
|
||||
|
||||
// The API does not have a GetDatabase endpoint, only ListDatabases
|
||||
func getDatabase(
|
||||
ctx context.Context,
|
||||
client *postgresflexalpha.APIClient,
|
||||
projectId, region, instanceId string,
|
||||
databaseId int64,
|
||||
) (*postgresflexalpha.ListDatabase, error) {
|
||||
// TODO - implement pagination handling
|
||||
resp, err := client.ListDatabasesRequestExecute(ctx, projectId, region, instanceId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if resp == nil || resp.Databases == nil {
|
||||
return nil, fmt.Errorf("response is nil")
|
||||
}
|
||||
for _, database := range *resp.Databases {
|
||||
if database.Id != nil && *database.Id == databaseId {
|
||||
return &database, nil
|
||||
}
|
||||
}
|
||||
return nil, errDatabaseNotFound
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue