Skip to content
This repository has been archived by the owner on Jan 29, 2025. It is now read-only.

Commit

Permalink
stop using append and just loop normally
Browse files Browse the repository at this point in the history
  • Loading branch information
Luiggi33 committed Aug 19, 2024
1 parent 140606c commit 5de7142
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions internal/provider/node_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,15 @@ func (r *nodeResource) Create(ctx context.Context, req resource.CreateRequest, r

plan.Allocations = make([]Allocation, len(nodeAllocations))

for _, allocation := range nodeAllocations {
plan.Allocations = append(plan.Allocations, Allocation{
for i, allocation := range nodeAllocations {
plan.Allocations[i] = Allocation{
ID: types.Int32Value(allocation.ID),
IP: types.StringValue(allocation.IP),
Alias: types.StringValue(allocation.Alias),
Port: types.Int32Value(allocation.Port),
Notes: types.StringValue(allocation.Notes),
Assigned: types.BoolValue(allocation.Assigned),
})
}
}

// Set state to fully populated data
Expand Down Expand Up @@ -353,15 +353,17 @@ func (r *nodeResource) Read(ctx context.Context, req resource.ReadRequest, resp
state.CreatedAt = types.StringValue(node.CreatedAt.Format(time.RFC3339))
state.UpdatedAt = types.StringValue(node.UpdatedAt.Format(time.RFC3339))

for _, allocation := range nodeAllocations {
state.Allocations = append(state.Allocations, Allocation{
state.Allocations = make([]Allocation, len(nodeAllocations))

for i, allocation := range nodeAllocations {
state.Allocations[i] = Allocation{
ID: types.Int32Value(allocation.ID),
IP: types.StringValue(allocation.IP),
Alias: types.StringValue(allocation.Alias),
Port: types.Int32Value(allocation.Port),
Notes: types.StringValue(allocation.Notes),
Assigned: types.BoolValue(allocation.Assigned),
})
}
}

// Set refreshed state
Expand Down Expand Up @@ -493,15 +495,15 @@ func (r *nodeResource) Update(ctx context.Context, req resource.UpdateRequest, r

plan.Allocations = make([]Allocation, len(nodeAllocations))

for _, allocation := range nodeAllocations {
plan.Allocations = append(plan.Allocations, Allocation{
for i, allocation := range nodeAllocations {
plan.Allocations[i] = Allocation{
ID: types.Int32Value(allocation.ID),
IP: types.StringValue(allocation.IP),
Alias: types.StringValue(allocation.Alias),
Port: types.Int32Value(allocation.Port),
Notes: types.StringValue(allocation.Notes),
Assigned: types.BoolValue(allocation.Assigned),
})
}
}

diags = resp.State.Set(ctx, plan)
Expand Down Expand Up @@ -599,15 +601,17 @@ func (r *nodeResource) ImportState(ctx context.Context, req resource.ImportState
return
}

for _, allocation := range nodeAllocations {
state.Allocations = append(state.Allocations, Allocation{
state.Allocations = make([]Allocation, len(nodeAllocations))

for i, allocation := range nodeAllocations {
state.Allocations[i] = Allocation{
ID: types.Int32Value(allocation.ID),
IP: types.StringValue(allocation.IP),
Alias: types.StringValue(allocation.Alias),
Port: types.Int32Value(allocation.Port),
Notes: types.StringValue(allocation.Notes),
Assigned: types.BoolValue(allocation.Assigned),
})
}
}

// Set state to fully populated data
Expand Down

0 comments on commit 5de7142

Please sign in to comment.