Skip to content

Commit a323e8e

Browse files
authored
Merge pull request #248 from NetApp/247-bug-panic-runtime-error-invalid-memory-address-or-nil-pointer-dereference
fix san igroup
2 parents f1f0587 + e105c89 commit a323e8e

File tree

6 files changed

+67
-47
lines changed

6 files changed

+67
-47
lines changed

.github/workflows/acc_test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525
TF_ACC_NETAPP_HOST2: ${{ secrets.TF_ACC_NETAPP_HOST2 }}
2626
TF_ACC_NETAPP_HOST3: ${{ secrets.TF_ACC_NETAPP_HOST3 }}
2727
TF_ACC_NETAPP_HOST4: ${{ secrets.TF_ACC_NETAPP_HOST4 }}
28+
TF_ACC_NETAPP_HOST5: ${{ secrets.TF_ACC_NETAPP_HOST5 }}
2829
TF_ACC_NETAPP_HOST_CIFS: ${{ secrets.TF_ACC_NETAPP_HOST_CIFS }}
2930
TF_ACC_NETAPP_USER: ${{ secrets.TF_ACC_NETAPP_USER }}
3031
TF_ACC_NETAPP_PASS: ${{ secrets.TF_ACC_NETAPP_PASS }}

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 1.1.3
2+
3+
BUG FIXES:
4+
* **netapp-ontap_protocols_san_igroups_resource**: fixed bug nil pointer dereference ([#247](https://github.com/NetApp/terraform-provider-netapp-ontap/issues/247))
5+
6+
17
## 1.1.2 (2024-06-03)
28

39
ENHANCEMENTS:

internal/interfaces/protocols_san_igroup.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ type Portset struct {
5656

5757
// ProtocolsSanIgroupResourceBodyDataModelONTAP describes the body data model using go types for mapping.
5858
type ProtocolsSanIgroupResourceBodyDataModelONTAP struct {
59-
Name string `mapstructure:"name"`
60-
SVM SvmDataModelONTAP `mapstructure:"svm"`
61-
OsType string `mapstructure:"os_type"`
62-
Protocol string `mapstructure:"protocol"`
63-
Comment string `mapstructure:"comment,omitempty"`
64-
Igroups []IgroupLun `mapstructure:"igroups,omitempty"`
65-
Initiators []IgroupInitiator `mapstructure:"initiators,omitempty"`
66-
Portset Portset `mapstructure:"portset,omitempty"`
59+
Name string `mapstructure:"name"`
60+
SVM SvmDataModelONTAP `mapstructure:"svm"`
61+
OsType string `mapstructure:"os_type"`
62+
Protocol string `mapstructure:"protocol"`
63+
Comment string `mapstructure:"comment,omitempty"`
64+
Igroups []map[string]interface{} `mapstructure:"igroups,omitempty"`
65+
Initiators []map[string]interface{} `mapstructure:"initiators,omitempty"`
66+
Portset Portset `mapstructure:"portset,omitempty"`
6767
}
6868

6969
// UpdateProtocolsSanIgroupResourceBodyDataModelONTAP describes the body data model using go types for mapping.

internal/provider/protocols_san_igroup_resource.go

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/hashicorp/terraform-plugin-framework/types"
1717
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
1818
"github.com/hashicorp/terraform-plugin-log/tflog"
19+
"github.com/mitchellh/mapstructure"
1920
"github.com/netapp/terraform-provider-netapp-ontap/internal/interfaces"
2021
"github.com/netapp/terraform-provider-netapp-ontap/internal/utils"
2122
)
@@ -40,16 +41,16 @@ type ProtocolsSanIgroupResource struct {
4041

4142
// ProtocolsSanIgroupResourceModel describes the resource data model.
4243
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"`
5354
}
5455

5556
// ProtocolsSanIgroupResourceIgroupModel describes the data source data model.
@@ -254,23 +255,35 @@ func (r *ProtocolsSanIgroupResource) Create(ctx context.Context, req resource.Cr
254255
if !data.Comment.IsUnknown() {
255256
body.Comment = data.Comment.ValueString()
256257
}
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
263270
}
264271
}
265272

266273
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
272284
}
273285
}
286+
274287
body.OsType = data.OsType.ValueString()
275288
if !data.Portset.IsUnknown() {
276289
var portset ProtocolsSanIgroupResourcePortsetModel
@@ -343,7 +356,7 @@ func (r *ProtocolsSanIgroupResource) Update(ctx context.Context, req resource.Up
343356
request.OsType = data.OsType.ValueString()
344357
}
345358

346-
tflog.Debug(ctx, fmt.Sprintf("update a svm resource: %#v", data))
359+
tflog.Debug(ctx, fmt.Sprintf("update an igroup resource: %#v", data))
347360
err = interfaces.UpdateProtocolsSanIgroup(errorHandler, *client, request, state.ID.ValueString())
348361
if err != nil {
349362
return

internal/provider/snapmirror_resource_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,31 @@ func TestAccSnapmirrorResource(t *testing.T) {
1616
Steps: []resource.TestStep{
1717
// Test non existant Vol
1818
{
19-
Config: testAccSnapmirrorResourceBasicConfig("snapmirror_dest_svm:testme", "snapmirror_dest_svm:testme"),
19+
Config: testAccSnapmirrorResourceBasicConfig("tf_peer:testme", "terraform:testme"),
2020
ExpectError: regexp.MustCompile("6619337"),
2121
},
2222
// Create snapmirror and read
2323
{
24-
Config: testAccSnapmirrorResourceBasicConfig("snapmirror_dest_svm:snap_dest3", "snapmirror_dest_svm:snap_dest2"),
24+
Config: testAccSnapmirrorResourceBasicConfig("tf_peer:snap_source2", "terraform:snap_dest2"),
2525
Check: resource.ComposeTestCheckFunc(
26-
resource.TestCheckResourceAttr("netapp-ontap_snapmirror_resource.example", "destination_endpoint.path", "snapmirror_dest_svm:snap_dest2"),
26+
resource.TestCheckResourceAttr("netapp-ontap_snapmirror_resource.example", "destination_endpoint.path", "terraform:snap_dest2"),
2727
),
2828
},
2929
// Update a policy
3030
{
31-
Config: testAccSnapmirrorResourceUpdateConfig("snapmirror_dest_svm:snap_dest", "snapmirror_source_svm:snap", "MirrorAndVault"),
31+
Config: testAccSnapmirrorResourceUpdateConfig("tf_peer:snap_source", "terraform:snap_dest", "MirrorAndVault"),
3232
Check: resource.ComposeTestCheckFunc(
3333
resource.TestCheckResourceAttr("netapp-ontap_snapmirror_resource.example", "policy.name", "MirrorAndVault"),
34-
resource.TestCheckResourceAttr("netapp-ontap_snapmirror_resource.example", "destination_endpoint.path", "snapmirror_source_svm:snap"),
34+
resource.TestCheckResourceAttr("netapp-ontap_snapmirror_resource.example", "destination_endpoint.path", "terraform:snap_dest"),
3535
),
3636
},
3737
// Import and read
3838
{
3939
ResourceName: "netapp-ontap_snapmirror_resource.example",
4040
ImportState: true,
41-
ImportStateId: fmt.Sprintf("%s,%s", "snapmirror_dest_svm:snap_dest2", "cluster4"),
41+
ImportStateId: fmt.Sprintf("%s,%s", "terraform:snap_dest", "cluster4"),
4242
Check: resource.ComposeTestCheckFunc(
43-
resource.TestCheckResourceAttr("netapp-ontap_snapmirror_resource.example", "destination_endpoint.path", "snapmirror_dest_svm:snap_dest2"),
43+
resource.TestCheckResourceAttr("netapp-ontap_snapmirror_resource.example", "destination_endpoint.path", "terraform:snap_dest"),
4444
),
4545
},
4646
// Delete testing automatically occurs in TestCase
@@ -49,11 +49,11 @@ func TestAccSnapmirrorResource(t *testing.T) {
4949
}
5050

5151
func testAccSnapmirrorResourceBasicConfig(sourceEndpoint string, destinationEndpoint string) string {
52-
host := os.Getenv("TF_ACC_NETAPP_HOST4")
52+
host := os.Getenv("TF_ACC_NETAPP_HOST5")
5353
admin := os.Getenv("TF_ACC_NETAPP_USER")
54-
password := os.Getenv("TF_ACC_NETAPP_PASS")
54+
password := os.Getenv("TF_ACC_NETAPP_PASS2")
5555
if host == "" || admin == "" || password == "" {
56-
fmt.Println("TF_ACC_NETAPP_HOST4, TF_ACC_NETAPP_USER, and TF_ACC_NETAPP_PASS must be set for acceptance tests")
56+
fmt.Println("TF_ACC_NETAPP_HOST5, TF_ACC_NETAPP_USER, and TF_ACC_NETAPP_PASS must be set for acceptance tests")
5757
os.Exit(1)
5858
}
5959
return fmt.Sprintf(`
@@ -81,11 +81,11 @@ resource "netapp-ontap_snapmirror_resource" "example" {
8181
}
8282

8383
func testAccSnapmirrorResourceUpdateConfig(sourceEndpoint string, destinationEndpoint string, policy string) string {
84-
host := os.Getenv("TF_ACC_NETAPP_HOST4")
84+
host := os.Getenv("TF_ACC_NETAPP_HOST5")
8585
admin := os.Getenv("TF_ACC_NETAPP_USER")
86-
password := os.Getenv("TF_ACC_NETAPP_PASS")
86+
password := os.Getenv("TF_ACC_NETAPP_PASS2")
8787
if host == "" || admin == "" || password == "" {
88-
fmt.Println("TF_ACC_NETAPP_HOST4, TF_ACC_NETAPP_USER, and TF_ACC_NETAPP_PASS must be set for acceptance tests")
88+
fmt.Println("TF_ACC_NETAPP_HOST5, TF_ACC_NETAPP_USER, and TF_ACC_NETAPP_PASS must be set for acceptance tests")
8989
os.Exit(1)
9090
}
9191
return fmt.Sprintf(`

internal/provider/svm_peers_resource_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func TestAccSvmPeersResource(t *testing.T) {
3939
{
4040
ResourceName: "netapp-ontap_svm_peers_resource.example",
4141
ImportState: true,
42-
ImportStateId: fmt.Sprintf("%s,%s,%s,%s", "snapmirror_dest_dp", "snapmirror_dest_svm", "swenjuncluster-1", "cluster4"),
42+
ImportStateId: fmt.Sprintf("%s,%s,%s,%s", "terraform", "tf_peer", "swenjuncluster-1", "cluster4"),
4343
Check: resource.ComposeTestCheckFunc(
4444
resource.TestCheckResourceAttr("netapp-ontap_svm_peers_resource.example", "svm.name", "snapmirror_dest_dp"),
4545
),
@@ -48,13 +48,13 @@ func TestAccSvmPeersResource(t *testing.T) {
4848
})
4949
}
5050
func testAccSvmPeersResourceConfig(svm, peerSvm, peerCluster, applications string) string {
51-
host := os.Getenv("TF_ACC_NETAPP_HOST4")
51+
host := os.Getenv("TF_ACC_NETAPP_HOST5")
5252
admin := os.Getenv("TF_ACC_NETAPP_USER")
5353
password := os.Getenv("TF_ACC_NETAPP_PASS")
5454
password2 := os.Getenv("TF_ACC_NETAPP_PASS2")
5555
host2 := os.Getenv("TF_ACC_NETAPP_HOST2")
5656
if host == "" || admin == "" || password == "" {
57-
fmt.Println("TF_ACC_NETAPP_HOST2, TF_ACC_NETAPP_HOST4, TF_ACC_NETAPP_USER, TF_ACC_NETAPP_PASS2 and TF_ACC_NETAPP_PASS must be set for acceptance tests")
57+
fmt.Println("TF_ACC_NETAPP_HOST2, TF_ACC_NETAPP_HOST5, TF_ACC_NETAPP_USER, TF_ACC_NETAPP_PASS2 and TF_ACC_NETAPP_PASS must be set for acceptance tests")
5858
os.Exit(1)
5959
}
6060
return fmt.Sprintf(`
@@ -92,5 +92,5 @@ resource "netapp-ontap_svm_peers_resource" "example" {
9292
peer_cx_profile_name = "cluster3"
9393
}
9494
applications = ["%s"]
95-
}`, host, admin, password, host2, admin, password2, svm, peerSvm, peerCluster, applications)
95+
}`, host, admin, password2, host2, admin, password2, svm, peerSvm, peerCluster, applications)
9696
}

0 commit comments

Comments
 (0)