From 27cb5401a63314dc198344f4d9b46b176b3850bd Mon Sep 17 00:00:00 2001 From: Philipp Sauter Date: Fri, 26 Jul 2024 14:54:16 +0200 Subject: [PATCH] fix --- pkg/resources/instance/resource.go | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/pkg/resources/instance/resource.go b/pkg/resources/instance/resource.go index d30f5047..3b4035a9 100644 --- a/pkg/resources/instance/resource.go +++ b/pkg/resources/instance/resource.go @@ -217,21 +217,6 @@ func Resource() *schema.Resource { } } -func findInstanceType(ctx context.Context, c *v3.Client, x string) (*v3.InstanceType, error) { - res, err := c.ListInstanceTypes(ctx) - if err != nil { - return nil, err - } - - for _, r := range res.InstanceTypes { - if r.ID.String() == x { - return c.GetInstanceType(ctx, r.ID) - } - } - - return nil, v3.ErrNotFound -} - func rCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { //nolint:gocyclo tflog.Debug(ctx, "beginning create", map[string]interface{}{ "id": utils.IDString(d, Name), @@ -1022,7 +1007,12 @@ func rApply( //nolint:gocyclo return diag.FromErr(err) } - instanceType, err := findInstanceType(ctx, clientV3, instance.InstanceType.ID.String()) + instanceTypes, err := clientV3.ListInstanceTypes(ctx) + if err != nil { + return diag.Errorf("unable to find instance type: %s", err) + } + + instanceType, err := instanceTypes.FindInstanceType(instance.InstanceType.ID.String()) if err != nil { return diag.Errorf("unable to find instance type: %s", err) }