Skip to content

Commit 1d978f9

Browse files
committed
chore(edgecloud): Update to new SDK structure
1 parent e855937 commit 1d978f9

12 files changed

Lines changed: 125 additions & 181 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ require (
1515
github.com/stackitcloud/stackit-sdk-go/services/alb v0.9.3
1616
github.com/stackitcloud/stackit-sdk-go/services/cdn v1.13.0
1717
github.com/stackitcloud/stackit-sdk-go/services/dns v0.19.1
18-
github.com/stackitcloud/stackit-sdk-go/services/edge v0.7.0
18+
github.com/stackitcloud/stackit-sdk-go/services/edge v0.8.0
1919
github.com/stackitcloud/stackit-sdk-go/services/git v0.10.3
2020
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.3.5
2121
github.com/stackitcloud/stackit-sdk-go/services/kms v1.3.2

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ github.com/stackitcloud/stackit-sdk-go/services/cdn v1.13.0 h1:iRJK2d3I2QqWp8hqh
161161
github.com/stackitcloud/stackit-sdk-go/services/cdn v1.13.0/go.mod h1:URWWMIbvq4YgWdGYCbccr3eat4Y+0qRpufZsEAsvoLM=
162162
github.com/stackitcloud/stackit-sdk-go/services/dns v0.19.1 h1:VfszhFq/Snsd0LnflS8PbM0d9cG98hOFpamfjlcTnDQ=
163163
github.com/stackitcloud/stackit-sdk-go/services/dns v0.19.1/go.mod h1:gBv6YkB3Xf3c0ZXg2GwtWY8zExwGPF/Ag114XiiERxg=
164-
github.com/stackitcloud/stackit-sdk-go/services/edge v0.7.0 h1:DNBiHWQEWXHSbaZBmnXb+CaPXX1uVsSfp4FTHoH4wrM=
165-
github.com/stackitcloud/stackit-sdk-go/services/edge v0.7.0/go.mod h1:CfqSEGCW0b5JlijCwtUT1kfjThmQ5jXX47TWrdD5rTU=
164+
github.com/stackitcloud/stackit-sdk-go/services/edge v0.8.0 h1:lsOTEvItzrUerCzUodyyOy6pZ4QiSzwID7U20ZvZvHw=
165+
github.com/stackitcloud/stackit-sdk-go/services/edge v0.8.0/go.mod h1:CfqSEGCW0b5JlijCwtUT1kfjThmQ5jXX47TWrdD5rTU=
166166
github.com/stackitcloud/stackit-sdk-go/services/git v0.10.3 h1:VIjkSofZz9utOOkBdNZCIb07P/JdKc1kHV1P8Rq9dLc=
167167
github.com/stackitcloud/stackit-sdk-go/services/git v0.10.3/go.mod h1:EJk1Ss9GTel2NPIu/w3+x9XcQcEd2k3ibea5aQDzVhQ=
168168
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.3.5 h1:W57+XRa8wTLsi5CV9Tqa7mGgt/PvlRM//RurXSmvII8=

stackit/internal/services/edgecloud/edge_acc_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import (
1717
"github.com/hashicorp/terraform-plugin-testing/terraform"
1818
coreConfig "github.com/stackitcloud/stackit-sdk-go/core/config"
1919
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
20-
"github.com/stackitcloud/stackit-sdk-go/services/edge"
21-
"github.com/stackitcloud/stackit-sdk-go/services/edge/wait"
20+
edge "github.com/stackitcloud/stackit-sdk-go/services/edge/v1beta1api"
21+
"github.com/stackitcloud/stackit-sdk-go/services/edge/v1beta1api/wait"
2222
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
2323
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/testutil"
2424
)
@@ -357,7 +357,7 @@ func testAccCheckEdgeCloudInstanceDestroy(s *terraform.State) error {
357357
}
358358
projectId, region, instanceId := idParts[0], idParts[1], idParts[2]
359359

360-
_, err := client.GetInstance(ctx, projectId, region, instanceId).Execute()
360+
_, err := client.DefaultAPI.GetInstance(ctx, projectId, region, instanceId).Execute()
361361
if err == nil {
362362
return fmt.Errorf("edge instance %q still exists", instanceId)
363363
}
@@ -366,11 +366,11 @@ func testAccCheckEdgeCloudInstanceDestroy(s *terraform.State) error {
366366
var oapiErr *oapierror.GenericOpenAPIError
367367
ok := errors.As(err, &oapiErr)
368368
if !ok || oapiErr.StatusCode != http.StatusNotFound {
369-
err := client.DeleteInstance(ctx, projectId, region, instanceId).Execute()
369+
err := client.DefaultAPI.DeleteInstance(ctx, projectId, region, instanceId).Execute()
370370
if err != nil {
371371
return fmt.Errorf("deleting instance %s during CheckDestroy: %w", instanceId, err)
372372
}
373-
_, err = wait.DeleteInstanceWaitHandler(ctx, client, projectId, region, instanceId).WaitWithContext(ctx)
373+
_, err = wait.DeleteInstanceWaitHandler(ctx, client.DefaultAPI, projectId, region, instanceId).WaitWithContext(ctx)
374374
if err != nil {
375375
return fmt.Errorf("waiting for instance deletion %s during CheckDestroy: %w", instanceId, err)
376376
}

stackit/internal/services/edgecloud/instance/resource.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import (
1818
"github.com/hashicorp/terraform-plugin-framework/types"
1919
"github.com/hashicorp/terraform-plugin-log/tflog"
2020
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
21-
"github.com/stackitcloud/stackit-sdk-go/services/edge"
22-
edgewait "github.com/stackitcloud/stackit-sdk-go/services/edge/wait"
21+
edge "github.com/stackitcloud/stackit-sdk-go/services/edge/v1beta1api"
22+
edgewait "github.com/stackitcloud/stackit-sdk-go/services/edge/v1beta1api/wait"
2323
"github.com/stackitcloud/stackit-sdk-go/services/serviceenablement"
2424
enablementWait "github.com/stackitcloud/stackit-sdk-go/services/serviceenablement/wait"
2525
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
@@ -264,7 +264,7 @@ func (i *instanceResource) Create(ctx context.Context, req resource.CreateReques
264264

265265
tflog.Info(ctx, "Creating new Edge Cloud instance")
266266
payload := toCreatePayload(&model)
267-
createResp, err := i.client.CreateInstance(ctx, projectId, region).CreateInstancePayload(payload).Execute()
267+
createResp, err := i.client.DefaultAPI.CreateInstance(ctx, projectId, region).CreateInstancePayload(payload).Execute()
268268
if err != nil {
269269
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating instance", fmt.Sprintf("Calling API: %v", err))
270270
return
@@ -276,12 +276,12 @@ func (i *instanceResource) Create(ctx context.Context, req resource.CreateReques
276276
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating instance", "API returned nil response")
277277
return
278278
}
279-
if createResp.Id == nil {
280-
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating instance", "API returned nil Instance ID")
279+
if createResp.Id == "" {
280+
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating instance", "API returned empty Instance ID")
281281
return
282282
}
283283

284-
edgeCloudInstanceId := *createResp.Id
284+
edgeCloudInstanceId := createResp.Id
285285
// Write id attributes to state before polling via the wait handler - just in case anything goes wrong during the wait handler
286286
ctx = utils.SetAndLogStateFields(ctx, &resp.Diagnostics, &resp.State, map[string]any{
287287
"project_id": projectId,
@@ -292,7 +292,7 @@ func (i *instanceResource) Create(ctx context.Context, req resource.CreateReques
292292
return
293293
}
294294

295-
waitResp, err := edgewait.CreateOrUpdateInstanceWaitHandler(ctx, i.client, projectId, region, edgeCloudInstanceId).WaitWithContext(ctx)
295+
waitResp, err := edgewait.CreateOrUpdateInstanceWaitHandler(ctx, i.client.DefaultAPI, projectId, region, edgeCloudInstanceId).WaitWithContext(ctx)
296296
if err != nil {
297297
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating instance", fmt.Sprintf("Instance waiting: %v", err))
298298
return
@@ -329,7 +329,7 @@ func (i *instanceResource) Read(ctx context.Context, req resource.ReadRequest, r
329329
ctx = tflog.SetField(ctx, "instance_id", instanceId)
330330
ctx = tflog.SetField(ctx, "region", region)
331331

332-
edgeCloudInstanceResp, err := i.client.GetInstance(ctx, projectId, region, instanceId).Execute()
332+
edgeCloudInstanceResp, err := i.client.DefaultAPI.GetInstance(ctx, projectId, region, instanceId).Execute()
333333
if err != nil {
334334
var oapiErr *oapierror.GenericOpenAPIError
335335
ok := errors.As(err, &oapiErr)
@@ -372,15 +372,15 @@ func (i *instanceResource) Update(ctx context.Context, req resource.UpdateReques
372372

373373
tflog.Info(ctx, "Updating Edge Cloud instance", map[string]any{"instance_id": instanceId})
374374
payload := toUpdatePayload(&model)
375-
err := i.client.UpdateInstance(ctx, projectId, region, instanceId).UpdateInstancePayload(payload).Execute()
375+
err := i.client.DefaultAPI.UpdateInstance(ctx, projectId, region, instanceId).UpdateInstancePayload(payload).Execute()
376376
if err != nil {
377377
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating instance", fmt.Sprintf("Calling API: %v", err))
378378
return
379379
}
380380

381381
ctx = core.LogResponse(ctx)
382382

383-
waitResp, err := edgewait.CreateOrUpdateInstanceWaitHandler(ctx, i.client, projectId, region, instanceId).WaitWithContext(ctx)
383+
waitResp, err := edgewait.CreateOrUpdateInstanceWaitHandler(ctx, i.client.DefaultAPI, projectId, region, instanceId).WaitWithContext(ctx)
384384
if err != nil {
385385
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating instance", fmt.Sprintf("Instance waiting: %v", err))
386386
return
@@ -414,15 +414,15 @@ func (i *instanceResource) Delete(ctx context.Context, req resource.DeleteReques
414414
ctx = tflog.SetField(ctx, "instance_id", instanceId)
415415
ctx = tflog.SetField(ctx, "region", region)
416416

417-
err := i.client.DeleteInstance(ctx, projectId, region, instanceId).Execute()
417+
err := i.client.DefaultAPI.DeleteInstance(ctx, projectId, region, instanceId).Execute()
418418
if err != nil {
419419
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting instance", fmt.Sprintf("Calling API: %v", err))
420420
return
421421
}
422422

423423
ctx = core.LogResponse(ctx)
424424

425-
_, err = edgewait.DeleteInstanceWaitHandler(ctx, i.client, projectId, region, instanceId).WaitWithContext(ctx)
425+
_, err = edgewait.DeleteInstanceWaitHandler(ctx, i.client.DefaultAPI, projectId, region, instanceId).WaitWithContext(ctx)
426426
if err != nil {
427427
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting instance", fmt.Sprintf("Instance deletion waiting: %v", err))
428428
return
@@ -461,8 +461,8 @@ func mapFields(resp *edge.Instance, model *Model) error {
461461
var instanceId string
462462
if model.InstanceId.ValueString() != "" {
463463
instanceId = model.InstanceId.ValueString()
464-
} else if resp.Id != nil {
465-
instanceId = *resp.Id
464+
} else if resp.Id != "" {
465+
instanceId = resp.Id
466466
}
467467
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), model.Region.ValueString(), instanceId)
468468
model.InstanceId = types.StringValue(instanceId)
@@ -471,10 +471,10 @@ func mapFields(resp *edge.Instance, model *Model) error {
471471
} else {
472472
model.Created = types.StringNull()
473473
}
474-
model.FrontendUrl = types.StringPointerValue(resp.FrontendUrl)
475-
model.DisplayName = types.StringPointerValue(resp.DisplayName)
476-
model.PlanID = types.StringPointerValue(resp.PlanId)
477-
model.Status = types.StringValue(string(*resp.Status))
474+
model.FrontendUrl = types.StringValue(resp.FrontendUrl)
475+
model.DisplayName = types.StringValue(resp.DisplayName)
476+
model.PlanID = types.StringValue(resp.PlanId)
477+
model.Status = types.StringValue(resp.Status)
478478

479479
if resp.Description != nil {
480480
model.Description = types.StringValue(*resp.Description)
@@ -488,9 +488,9 @@ func mapFields(resp *edge.Instance, model *Model) error {
488488
// toCreatePayload creates the payload for creating an Edge Cloud instance.
489489
func toCreatePayload(model *Model) edge.CreateInstancePayload {
490490
return edge.CreateInstancePayload{
491-
DisplayName: model.DisplayName.ValueStringPointer(),
491+
DisplayName: model.DisplayName.ValueString(),
492492
Description: model.Description.ValueStringPointer(),
493-
PlanId: model.PlanID.ValueStringPointer(),
493+
PlanId: model.PlanID.ValueString(),
494494
}
495495
}
496496

stackit/internal/services/edgecloud/instance/resource_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/google/uuid"
1010
"github.com/hashicorp/terraform-plugin-framework/types"
1111
"github.com/stackitcloud/stackit-sdk-go/core/utils"
12-
"github.com/stackitcloud/stackit-sdk-go/services/edge"
12+
edge "github.com/stackitcloud/stackit-sdk-go/services/edge/v1beta1api"
1313
)
1414

1515
func TestMapFields(t *testing.T) {
@@ -25,13 +25,13 @@ func TestMapFields(t *testing.T) {
2525
{
2626
"all_parameter_set",
2727
&edge.Instance{
28-
Id: utils.Ptr("iid-123"),
29-
Created: &testTime,
30-
DisplayName: utils.Ptr("test-instance"),
28+
Id: "iid-123",
29+
Created: testTime,
30+
DisplayName: "test-instance",
3131
Description: utils.Ptr("Test description"),
32-
PlanId: utils.Ptr(uuidString),
33-
Status: utils.Ptr(edge.InstanceStatus("CREATING")),
34-
FrontendUrl: utils.Ptr("https://iid-123.example.com"),
32+
PlanId: uuidString,
33+
Status: "CREATING",
34+
FrontendUrl: "https://iid-123.example.com",
3535
},
3636
&Model{
3737
ProjectId: types.StringValue(uuidString),
@@ -54,13 +54,13 @@ func TestMapFields(t *testing.T) {
5454
{
5555
"empty_description",
5656
&edge.Instance{
57-
Id: utils.Ptr("iid-123"),
58-
Created: &testTime,
59-
DisplayName: utils.Ptr("test-instance"),
57+
Id: "iid-123",
58+
Created: testTime,
59+
DisplayName: "test-instance",
6060
Description: utils.Ptr(""),
61-
PlanId: utils.Ptr(uuidString),
62-
Status: utils.Ptr(edge.InstanceStatus("ACTIVE")),
63-
FrontendUrl: utils.Ptr("https://iid-123.example.com"),
61+
PlanId: uuidString,
62+
Status: "ACTIVE",
63+
FrontendUrl: "https://iid-123.example.com",
6464
},
6565
&Model{
6666
ProjectId: types.StringValue(uuidString),
@@ -132,9 +132,9 @@ func TestToCreatePayload(t *testing.T) {
132132
PlanID: types.StringValue(uuidString),
133133
},
134134
edge.CreateInstancePayload{
135-
DisplayName: utils.Ptr("new-instance"),
135+
DisplayName: "new-instance",
136136
Description: utils.Ptr("A new test instance"),
137-
PlanId: utils.Ptr(uuidString),
137+
PlanId: uuidString,
138138
},
139139
true,
140140
},
@@ -146,9 +146,9 @@ func TestToCreatePayload(t *testing.T) {
146146
PlanID: types.StringValue(uuidString),
147147
},
148148
edge.CreateInstancePayload{
149-
DisplayName: utils.Ptr("new-instance"),
149+
DisplayName: "new-instance",
150150
Description: nil,
151-
PlanId: utils.Ptr(uuidString),
151+
PlanId: uuidString,
152152
},
153153
true,
154154
},

stackit/internal/services/edgecloud/instances/datasource.go

Lines changed: 13 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
1313
"github.com/hashicorp/terraform-plugin-framework/types"
1414
"github.com/hashicorp/terraform-plugin-log/tflog"
15-
"github.com/stackitcloud/stackit-sdk-go/services/edge"
15+
edge "github.com/stackitcloud/stackit-sdk-go/services/edge/v1beta1api"
1616
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
1717
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
1818
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/features"
@@ -166,7 +166,7 @@ func (d *instancesDataSource) Read(ctx context.Context, req datasource.ReadReque
166166
ctx = tflog.SetField(ctx, "region", region)
167167

168168
// Fetch all instances for the project and region
169-
instancesResp, err := d.client.ListInstances(ctx, projectId, region).Execute()
169+
instancesResp, err := d.client.DefaultAPI.ListInstances(ctx, projectId, region).Execute()
170170
if err != nil {
171171
utils.LogError(
172172
ctx,
@@ -216,20 +216,11 @@ func (d *instancesDataSource) Read(ctx context.Context, req datasource.ReadReque
216216
}
217217

218218
// buildInstancesList constructs a list of instance attributes
219-
func buildInstancesList(ctx context.Context, instances edge.InstanceListGetInstancesAttributeType, region string, diags *diag.Diagnostics) []attr.Value {
219+
func buildInstancesList(_ context.Context, instances []edge.Instance, region string, diags *diag.Diagnostics) []attr.Value {
220220
var instancesList []attr.Value
221221

222-
for _, instance := range *instances {
223-
instanceAttrs, err := mapInstanceToAttrs(instance, region)
224-
if err != nil {
225-
// Keep going in case there are more errors
226-
instanceId := "without id"
227-
if instance.Id != nil {
228-
instanceId = *instance.Id
229-
}
230-
core.LogAndAddError(ctx, diags, "Error reading instances", fmt.Sprintf("Could not process instance %q: %v", instanceId, err))
231-
continue
232-
}
222+
for _, instance := range instances {
223+
instanceAttrs := mapInstanceToAttrs(&instance, region)
233224

234225
instanceObjectValue, objDiags := types.ObjectValue(instanceTypes, instanceAttrs)
235226
diags.Append(objDiags...)
@@ -242,38 +233,16 @@ func buildInstancesList(ctx context.Context, instances edge.InstanceListGetInsta
242233
return instancesList
243234
}
244235

245-
func mapInstanceToAttrs(instance edge.Instance, region string) (map[string]attr.Value, error) {
246-
if instance.Id == nil {
247-
return nil, fmt.Errorf("instance is missing an 'id'")
248-
}
249-
if instance.DisplayName == nil || *instance.DisplayName == "" {
250-
return nil, fmt.Errorf("instance %q is missing a 'displayName'", *instance.Id)
251-
}
252-
if instance.PlanId == nil {
253-
return nil, fmt.Errorf("instance %q is missing a 'planId'", *instance.Id)
254-
}
255-
if instance.FrontendUrl == nil {
256-
return nil, fmt.Errorf("instance %q is missing a 'frontendUrl'", *instance.Id)
257-
}
258-
if instance.Status == nil {
259-
return nil, fmt.Errorf("instance %q is missing a 'status'", *instance.Id)
260-
}
261-
if instance.Created == nil {
262-
return nil, fmt.Errorf("instance %q is missing a 'created' timestamp", *instance.Id)
263-
}
264-
if instance.Description == nil {
265-
return nil, fmt.Errorf("instance %q is missing a 'description'", *instance.Id)
266-
}
267-
236+
func mapInstanceToAttrs(instance *edge.Instance, region string) map[string]attr.Value {
268237
attrs := map[string]attr.Value{
269-
"instance_id": types.StringValue(*instance.Id),
270-
"display_name": types.StringValue(*instance.DisplayName),
238+
"instance_id": types.StringValue(instance.Id),
239+
"display_name": types.StringValue(instance.DisplayName),
271240
"region": types.StringValue(region),
272-
"plan_id": types.StringValue(*instance.PlanId),
273-
"frontend_url": types.StringValue(*instance.FrontendUrl),
274-
"status": types.StringValue(string(instance.GetStatus())),
241+
"plan_id": types.StringValue(instance.PlanId),
242+
"frontend_url": types.StringValue(instance.FrontendUrl),
243+
"status": types.StringValue(instance.Status),
275244
"created": types.StringValue(instance.Created.String()),
276-
"description": types.StringValue(*instance.Description),
245+
"description": types.StringPointerValue(instance.Description),
277246
}
278-
return attrs, nil
247+
return attrs
279248
}

0 commit comments

Comments
 (0)