@@ -16,6 +16,7 @@ import (
16
16
"github.com/hashicorp/terraform-plugin-framework/types"
17
17
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
18
18
"github.com/hashicorp/terraform-plugin-log/tflog"
19
+ "github.com/mitchellh/mapstructure"
19
20
"github.com/netapp/terraform-provider-netapp-ontap/internal/interfaces"
20
21
"github.com/netapp/terraform-provider-netapp-ontap/internal/utils"
21
22
)
@@ -40,16 +41,16 @@ type ProtocolsSanIgroupResource struct {
40
41
41
42
// ProtocolsSanIgroupResourceModel describes the resource data model.
42
43
type ProtocolsSanIgroupResourceModel struct {
43
- CxProfileName types.String `tfsdk:"cx_profile_name"`
44
- Name types.String `tfsdk:"name"`
45
- SVM SVM `tfsdk:"svm"`
46
- Comment types.String `tfsdk:"comment"`
47
- Igroups * []ProtocolsSanIgroupResourceIgroupModel `tfsdk:"igroups"`
48
- Initiators * []ProtocolsSanIgroupResourceInitiatorModel `tfsdk:"initiators"`
49
- OsType types.String `tfsdk:"os_type"`
50
- Portset types.Object `tfsdk:"portset"`
51
- Protocol types.String `tfsdk:"protocol"`
52
- ID types.String `tfsdk:"id"`
44
+ CxProfileName types.String `tfsdk:"cx_profile_name"`
45
+ Name types.String `tfsdk:"name"`
46
+ SVM SVM `tfsdk:"svm"`
47
+ Comment types.String `tfsdk:"comment"`
48
+ Igroups []ProtocolsSanIgroupResourceIgroupModel `tfsdk:"igroups"`
49
+ Initiators []ProtocolsSanIgroupResourceInitiatorModel `tfsdk:"initiators"`
50
+ OsType types.String `tfsdk:"os_type"`
51
+ Portset types.Object `tfsdk:"portset"`
52
+ Protocol types.String `tfsdk:"protocol"`
53
+ ID types.String `tfsdk:"id"`
53
54
}
54
55
55
56
// ProtocolsSanIgroupResourceIgroupModel describes the data source data model.
@@ -254,23 +255,35 @@ func (r *ProtocolsSanIgroupResource) Create(ctx context.Context, req resource.Cr
254
255
if ! data .Comment .IsUnknown () {
255
256
body .Comment = data .Comment .ValueString ()
256
257
}
257
- if data .Initiators != nil {
258
- body .Igroups = make ([]interfaces.IgroupLun , len (* data .Igroups ))
259
- for index , record := range * data .Igroups {
260
- body .Igroups [index ] = interfaces.IgroupLun {
261
- Name : record .Name .ValueString (),
262
- }
258
+
259
+ if data .Igroups != nil {
260
+ igroups := []interfaces.IgroupLun {}
261
+ for _ , igroup := range data .Igroups {
262
+ var ig interfaces.IgroupLun
263
+ ig .Name = igroup .Name .ValueString ()
264
+ igroups = append (igroups , ig )
265
+ }
266
+ err := mapstructure .Decode (igroups , & body .Igroups )
267
+ if err != nil {
268
+ errorHandler .MakeAndReportError ("error creating igroups" , fmt .Sprintf ("error on encoding copies info: %s, copies %#v" , err , igroups ))
269
+ return
263
270
}
264
271
}
265
272
266
273
if data .Initiators != nil {
267
- body .Initiators = make ([]interfaces.IgroupInitiator , len (* data .Initiators ))
268
- for index , record := range * data .Initiators {
269
- body .Initiators [index ] = interfaces.IgroupInitiator {
270
- Name : record .Name .ValueString (),
271
- }
274
+ initiators := []interfaces.IgroupInitiator {}
275
+ for _ , v := range data .Igroups {
276
+ var initiator interfaces.IgroupInitiator
277
+ initiator .Name = v .Name .ValueString ()
278
+ initiators = append (initiators , initiator )
279
+ }
280
+ err := mapstructure .Decode (initiators , & body .Initiators )
281
+ if err != nil {
282
+ errorHandler .MakeAndReportError ("error creating igroups" , fmt .Sprintf ("error on encoding copies info: %s, copies %#v" , err , initiators ))
283
+ return
272
284
}
273
285
}
286
+
274
287
body .OsType = data .OsType .ValueString ()
275
288
if ! data .Portset .IsUnknown () {
276
289
var portset ProtocolsSanIgroupResourcePortsetModel
@@ -343,7 +356,7 @@ func (r *ProtocolsSanIgroupResource) Update(ctx context.Context, req resource.Up
343
356
request .OsType = data .OsType .ValueString ()
344
357
}
345
358
346
- tflog .Debug (ctx , fmt .Sprintf ("update a svm resource: %#v" , data ))
359
+ tflog .Debug (ctx , fmt .Sprintf ("update an igroup resource: %#v" , data ))
347
360
err = interfaces .UpdateProtocolsSanIgroup (errorHandler , * client , request , state .ID .ValueString ())
348
361
if err != nil {
349
362
return
0 commit comments