Skip to content

Commit

Permalink
Add separate function to get resize opts for datastore resize
Browse files Browse the repository at this point in the history
  • Loading branch information
Gogen120 committed Sep 23, 2024
1 parent 871724e commit 68fc5f2
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions selectel/dbaas.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func updateDatastoreBackups(ctx context.Context, d *schema.ResourceData, client
return nil
}

func resizeDatastore(ctx context.Context, d *schema.ResourceData, client *dbaas.API) error {
func getResizeOpts(ctx context.Context, d *schema.ResourceData, client *dbaas.API) (error, dbaas.DatastoreResizeOpts) {

Check failure on line 323 in selectel/dbaas.go

View workflow job for this annotation

GitHub Actions / golangci-lint

error-return: error should be the last type when returning multiple items (revive)
var resizeOpts dbaas.DatastoreResizeOpts
nodeCount := d.Get("node_count").(int)
resizeOpts.NodeCount = nodeCount
Expand All @@ -333,21 +333,30 @@ func resizeDatastore(ctx context.Context, d *schema.ResourceData, client *dbaas.
flavorSet := flavorRaw.(*schema.Set)
flavor, err := resourceDBaaSDatastoreV1FlavorFromSet(flavorSet)
if err != nil {
return errParseDatastoreV1Resize(err)
return errParseDatastoreV1Resize(err), resizeOpts
}
resizeOpts.Flavor = flavor
}

typeID := d.Get("type_id").(string)
datastoreType, err := client.DatastoreType(ctx, typeID)
if err != nil {
return errors.New("Couldnt get datastore type with id" + typeID)
return errors.New("Couldnt get datastore type with id" + typeID), resizeOpts
}

if datastoreType.Engine == "redis" {
resizeOpts.Flavor = nil
}

return nil, resizeOpts
}

func resizeDatastore(ctx context.Context, d *schema.ResourceData, client *dbaas.API) error {
err, resizeOpts := getResizeOpts(ctx, d, client)
if err != nil {
return errUpdatingObject(objectDatastore, d.Id(), err)
}

log.Print(msgUpdate(objectDatastore, d.Id(), resizeOpts))
_, err = client.ResizeDatastore(ctx, d.Id(), resizeOpts)
if err != nil {
Expand Down

0 comments on commit 68fc5f2

Please sign in to comment.