From 68fc5f231ae3993677fe7fa5028af105b8d4c044 Mon Sep 17 00:00:00 2001 From: Gogen120 Date: Mon, 23 Sep 2024 11:05:14 +0300 Subject: [PATCH] Add separate function to get resize opts for datastore resize --- selectel/dbaas.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/selectel/dbaas.go b/selectel/dbaas.go index 4648a65b..c9aea2a1 100644 --- a/selectel/dbaas.go +++ b/selectel/dbaas.go @@ -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) { var resizeOpts dbaas.DatastoreResizeOpts nodeCount := d.Get("node_count").(int) resizeOpts.NodeCount = nodeCount @@ -333,7 +333,7 @@ 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 } @@ -341,13 +341,22 @@ func resizeDatastore(ctx context.Context, d *schema.ResourceData, client *dbaas. 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 {