Skip to content

Commit

Permalink
fix: review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
marceljk committed Jan 29, 2025
1 parent a43d888 commit 3a31a27
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions stackit/internal/services/iaas/affinitygroup/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ func mapFields(ctx context.Context, affinityGroupResp *iaas.AffinityGroup, model
return fmt.Errorf("response input is nil")
}

if model == nil {
return fmt.Errorf("nil model")
}

var affinityGroupId string
if model.AffinityGroupId.ValueString() != "" {
affinityGroupId = model.AffinityGroupId.ValueString()
Expand All @@ -340,24 +344,20 @@ func mapFields(ctx context.Context, affinityGroupResp *iaas.AffinityGroup, model
strings.Join(idParts, core.Separator),
)

members, diags := types.ListValueFrom(ctx, types.StringType, []string{})
if diags.HasError() {
return fmt.Errorf("convert members to StringValue list: %w", core.DiagsToError(diags))
}
if affinityGroupResp.Members != nil && len(*affinityGroupResp.Members) > 0 {
members, diags = types.ListValueFrom(ctx, types.StringType, *affinityGroupResp.Members)
members, diags := types.ListValueFrom(ctx, types.StringType, *affinityGroupResp.Members)
if diags.HasError() {
return fmt.Errorf("convert members to StringValue list: %w", core.DiagsToError(diags))
}
model.Members = members
} else if model.Members.IsNull() {
members = types.ListNull(types.StringType)
model.Members = types.ListNull(types.StringType)
}

model.AffinityGroupId = types.StringValue(affinityGroupId)

model.Name = types.StringPointerValue(affinityGroupResp.Name)
model.Policy = types.StringPointerValue(affinityGroupResp.Policy)
model.Members = members

return nil
}

0 comments on commit 3a31a27

Please sign in to comment.