Skip to content

Commit

Permalink
Revert "Merge branch 'integration/main' of https://github.com/NetApp/…
Browse files Browse the repository at this point in the history
…terraform-provider-netapp-ontap into integration/main"

This reverts commit 1a4ab58, reversing
changes made to 307d865.
  • Loading branch information
wenjun666 committed Oct 7, 2024
1 parent 1a4ab58 commit 41f304d
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 80 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ DOC FIXES:

BUG FIXES:
* **netapp-ontap_cluster_data_source: fix on nodes to show multiple elements ([#264](https://github.com/NetApp/terraform-provider-netapp-ontap/issues/264))
* **netapp-ontap_protocols_nfs_export_policy_resource: fix id error during the creation ([[#290](https://github.com/NetApp/terraform-provider-netapp-ontap/issues/290)])

## 1.1.3 (2024-08-08)

Expand Down
33 changes: 13 additions & 20 deletions internal/interfaces/protocols_nfs_export_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,11 @@ type ExportpolicyResourceModel struct {
ID int `mapstructure:"id"`
}

// ExportpolicyResourceBodyDataModelONTAP describes the resource data model.
type ExportpolicyResourceBodyDataModelONTAP struct {
Name string `mapstructure:"name"`
Svm SvmDataModelONTAP `mapstructure:"svm"`
}

// ExportPolicyGetDataModelONTAP describes the GET record data model using go types for mapping.
type ExportPolicyGetDataModelONTAP struct {
Name string `mapstructure:"name"`
Svm string `mapstructure:"svm_name"`
SvmUUID string `mapstructure:"svm_uuid"`
ID int `mapstructure:"id"`
Name string `mapstructure:"name"`
Svm string `mapstructure:"svm_name"`
ID int `mapstructure:"id"`
}

// ExportPolicyGetDataFilterModel describes filter model
Expand All @@ -37,7 +30,7 @@ type ExportPolicyGetDataFilterModel struct {
}

// CreateExportPolicy to create export policy
func CreateExportPolicy(errorHandler *utils.ErrorHandler, r restclient.RestClient, data ExportpolicyResourceBodyDataModelONTAP) (*ExportpolicyResourceModel, error) {
func CreateExportPolicy(errorHandler *utils.ErrorHandler, r restclient.RestClient, data ExportpolicyResourceModel) (*ExportPolicyGetDataModelONTAP, error) {
var body map[string]interface{}
if err := mapstructure.Decode(data, &body); err != nil {
return nil, errorHandler.MakeAndReportError("error encoding export policy body", fmt.Sprintf("error on encoding export policy body: %s, body: %#v", err, data))
Expand All @@ -49,7 +42,7 @@ func CreateExportPolicy(errorHandler *utils.ErrorHandler, r restclient.RestClien
return nil, errorHandler.MakeAndReportError("error creating export policy", fmt.Sprintf("error on POST protocols/nfs/export-policies: %s, statusCode %d", err, statusCode))
}

var dataONTAP ExportpolicyResourceModel
var dataONTAP ExportPolicyGetDataModelONTAP
if err := mapstructure.Decode(response.Records[0], &dataONTAP); err != nil {
return nil, errorHandler.MakeAndReportError("error decoding export policies info", fmt.Sprintf("error on decode protocols/nfs/export-policies info: %s, statusCode %d, response %#v", err, statusCode, response))
}
Expand All @@ -58,7 +51,7 @@ func CreateExportPolicy(errorHandler *utils.ErrorHandler, r restclient.RestClien
}

// GetExportPolicy to get export policy
func GetExportPolicy(errorHandler *utils.ErrorHandler, r restclient.RestClient, id string) (*ExportpolicyResourceModel, error) {
func GetExportPolicy(errorHandler *utils.ErrorHandler, r restclient.RestClient, id string) (*ExportPolicyGetDataModelONTAP, error) {
api := "protocols/nfs/export-policies/" + id
statusCode, response, err := r.GetNilOrOneRecord(api, nil, nil)
if err == nil && response == nil {
Expand All @@ -68,7 +61,7 @@ func GetExportPolicy(errorHandler *utils.ErrorHandler, r restclient.RestClient,
return nil, errorHandler.MakeAndReportError("error reading export policy info", fmt.Sprintf("error on GET protocols/nfs/export-policies/%s: %s", id, err))
}

var dataONTAP ExportpolicyResourceModel
var dataONTAP ExportPolicyGetDataModelONTAP
if err := mapstructure.Decode(response, &dataONTAP); err != nil {
return nil, errorHandler.MakeAndReportError("error decoding export policy info", fmt.Sprintf("error on decode protocols/nfs/export-policies/%s: %s, statusCode %d, response %#v", id, err, statusCode, response))
}
Expand All @@ -77,7 +70,7 @@ func GetExportPolicy(errorHandler *utils.ErrorHandler, r restclient.RestClient,
}

// GetNfsExportPolicyByName to get export policy by filter
func GetNfsExportPolicyByName(errorHandler *utils.ErrorHandler, r restclient.RestClient, filter interface{}) (*ExportpolicyResourceModel, error) {
func GetNfsExportPolicyByName(errorHandler *utils.ErrorHandler, r restclient.RestClient, filter interface{}) (*ExportPolicyGetDataModelONTAP, error) {
query := r.NewQuery()
query.Fields([]string{"name"})
if filter != nil {
Expand All @@ -92,7 +85,7 @@ func GetNfsExportPolicyByName(errorHandler *utils.ErrorHandler, r restclient.Res
return nil, errorHandler.MakeAndReportError("error reading export policy info", fmt.Sprintf("error on GET protocols/nfs/export-policies: %s", err))
}

var dataONTAP ExportpolicyResourceModel
var dataONTAP ExportPolicyGetDataModelONTAP
if err := mapstructure.Decode(response, &dataONTAP); err != nil {
return nil, errorHandler.MakeAndReportError("error decoding export policy info", fmt.Sprintf("error on decode protocols/nfs/export-policies: %s, statusCode %d, response %#v", err, statusCode, response))
}
Expand All @@ -101,7 +94,7 @@ func GetNfsExportPolicyByName(errorHandler *utils.ErrorHandler, r restclient.Res
}

// GetExportPoliciesList to get export policies
func GetExportPoliciesList(errorHandler *utils.ErrorHandler, r restclient.RestClient, filter *ExportPolicyGetDataFilterModel) ([]ExportPolicyGetDataModelONTAP, error) {
func GetExportPoliciesList(errorHandler *utils.ErrorHandler, r restclient.RestClient, filter *ExportPolicyGetDataFilterModel) ([]ExportpolicyResourceModel, error) {
api := "protocols/nfs/export-policies"
query := r.NewQuery()
query.Fields([]string{"name", "id", "svm.name", "svm.uuid"})
Expand All @@ -120,9 +113,9 @@ func GetExportPoliciesList(errorHandler *utils.ErrorHandler, r restclient.RestCl
return nil, errorHandler.MakeAndReportError("error reading export policies info", fmt.Sprintf("error on GET %s: %s, statusCode %d", api, err, statusCode))
}

var dataONTAP []ExportPolicyGetDataModelONTAP
var dataONTAP []ExportpolicyResourceModel
for _, info := range response {
var record ExportPolicyGetDataModelONTAP
var record ExportpolicyResourceModel
if err := mapstructure.Decode(info, &record); err != nil {
return nil, errorHandler.MakeAndReportError(fmt.Sprintf("failed to decode response from GET %s", api),
fmt.Sprintf("error: %s, statusCode %d, info %#v", err, statusCode, info))
Expand All @@ -143,7 +136,7 @@ func DeleteExportPolicy(errorHandler *utils.ErrorHandler, r restclient.RestClien
}

// UpdateExportPolicy updates export policy
func UpdateExportPolicy(errorHandler *utils.ErrorHandler, r restclient.RestClient, data ExportpolicyResourceBodyDataModelONTAP, id string) error {
func UpdateExportPolicy(errorHandler *utils.ErrorHandler, r restclient.RestClient, data ExportpolicyResourceModel, id string) error {
var body map[string]interface{}
if err := mapstructure.Decode(data, &body); err != nil {
return errorHandler.MakeAndReportError("error encoding export policy body", fmt.Sprintf("error on encoding export policy body: %s, body: %#v", err, data))
Expand Down
43 changes: 18 additions & 25 deletions internal/interfaces/protocols_nfs_export_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,56 +13,49 @@ import (
"github.com/netapp/terraform-provider-netapp-ontap/internal/utils"
)

// basic get data records
var oneBasicExportPolicyRecord = ExportPolicyGetDataModelONTAP{
Name: "string",
Svm: "string",
SvmUUID: "string",
ID: 123,
}

// basic get data record
var basicExportPolicyRecord = ExportpolicyResourceModel{
var basicExportPolicyRecord = ExportPolicyGetDataModelONTAP{
Name: "string",
Svm: SvmDataModelONTAP{
Name: "string",
UUID: "string",
},
Svm: "string",
ID: 122880,
}

// bad record
var badExportPolicyRecord = struct{ Name int }{123}

// create export policy with basic request body
var basicExportPolicyBody = ExportpolicyResourceBodyDataModelONTAP{
var basicExportPolicyBody = ExportpolicyResourceModel{
Name: "string",
Svm: SvmDataModelONTAP{
Name: "string",
UUID: "string",
},
ID: 122880,
}

// create export policy with empty comment
var badExportPolicyBody = ExportpolicyResourceBodyDataModelONTAP{
var badExportPolicyBody = ExportpolicyResourceModel{
Name: "",
}

// update export policy name
var renameExportPolicyBody = ExportpolicyResourceBodyDataModelONTAP{
var renameExportPolicyBody = ExportpolicyResourceModel{
Name: "newname",
Svm: SvmDataModelONTAP{
Name: "string",
UUID: "string",
},
ID: 122880,
}

// update export policy with basic request body
var updateExportPolicyErrorBody = ExportpolicyResourceBodyDataModelONTAP{
var updateExportPolicyErrorBody = ExportpolicyResourceModel{
Name: "string",
Svm: SvmDataModelONTAP{
Name: "newsvm",
UUID: "string",
},
ID: 122880,
}

func TestGetExportPolicy(t *testing.T) {
Expand Down Expand Up @@ -100,7 +93,7 @@ func TestGetExportPolicy(t *testing.T) {
tests := []struct {
name string
responses []restclient.MockResponse
want *ExportpolicyResourceModel
want *ExportPolicyGetDataModelONTAP
wantErr bool
}{
{name: "test_no_records_1", responses: responses["test_no_records_1"], want: nil, wantErr: true},
Expand Down Expand Up @@ -155,8 +148,8 @@ func TestCreateExportPolicy(t *testing.T) {
tests := []struct {
name string
responses []restclient.MockResponse
requestbody ExportpolicyResourceBodyDataModelONTAP
want *ExportpolicyResourceModel
requestbody ExportpolicyResourceModel
want *ExportPolicyGetDataModelONTAP
wantErr bool
}{
{name: "test_create_basic_record_1", responses: responses["test_create_basic_record_1"], requestbody: basicExportPolicyBody, want: &basicExportPolicyRecord, wantErr: false},
Expand Down Expand Up @@ -236,7 +229,7 @@ func TestUpdateExportPolicy(t *testing.T) {
tests := []struct {
name string
responses []restclient.MockResponse
requestbody ExportpolicyResourceBodyDataModelONTAP
requestbody ExportpolicyResourceModel
wantErr bool
}{
{name: "test_update_rename_export_policy", responses: responses["test_update_rename_export_policy"], requestbody: renameExportPolicyBody, wantErr: false},
Expand Down Expand Up @@ -264,7 +257,7 @@ func TestGetExportPoliciesList(t *testing.T) {
errorHandler := utils.NewErrorHandler(context.Background(), &diag.Diagnostics{})
badRecord := struct{ Name int }{123}
var recordInterface map[string]any
err := mapstructure.Decode(oneBasicExportPolicyRecord, &recordInterface)
err := mapstructure.Decode(basicExportPolicyBody, &recordInterface)
if err != nil {
panic(err)
}
Expand All @@ -279,8 +272,8 @@ func TestGetExportPoliciesList(t *testing.T) {
twoRecordsResponse := restclient.RestResponse{NumRecords: 2, Records: []map[string]any{recordInterface, recordInterface}}
badRecordResponse := restclient.RestResponse{NumRecords: 1, Records: []map[string]any{badRecordInterface}}

var wantOneRecord = []ExportPolicyGetDataModelONTAP{oneBasicExportPolicyRecord}
var wantTwoRecords = []ExportPolicyGetDataModelONTAP{oneBasicExportPolicyRecord, oneBasicExportPolicyRecord}
var wantOneRecord = []ExportpolicyResourceModel{basicExportPolicyBody}
var wantTwoRecords = []ExportpolicyResourceModel{basicExportPolicyBody, basicExportPolicyBody}

responses := map[string][]restclient.MockResponse{
"test_no_records_1": {
Expand All @@ -301,7 +294,7 @@ func TestGetExportPoliciesList(t *testing.T) {
name string
responses []restclient.MockResponse
// args args
want []ExportPolicyGetDataModelONTAP
want []ExportpolicyResourceModel
wantErr bool
}{
{name: "test_no_records_1", responses: responses["test_no_records_1"], want: nil, wantErr: false},
Expand Down
18 changes: 2 additions & 16 deletions internal/interfaces/protocols_nfs_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package interfaces

import (
"fmt"

"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/mitchellh/mapstructure"
"github.com/netapp/terraform-provider-netapp-ontap/internal/restclient"
Expand All @@ -22,19 +21,6 @@ type ProtocolsNfsServiceGetDataModelONTAP struct {
SVM SvmDataModelONTAP `mapstructure:"svm"`
}

// ProtocolsNfsServiceResourceDataModelONTAP describes the GET record data model using go types for mapping.
type ProtocolsNfsServiceResourceDataModelONTAP struct {
Enabled bool `mapstructure:"enabled"`
Protocol Protocol `mapstructure:"protocol"`
Root Root `mapstructure:"root"`
Security Security `mapstructure:"security"`
ShowmountEnabled bool `mapstructure:"showmount_enabled"`
Transport Transport `mapstructure:"transport"`
VstorageEnabled bool `mapstructure:"vstorage_enabled"`
Windows Windows `mapstructure:"windows"`
SVM SvmDataModelONTAP `mapstructure:"svm"`
}

// Protocol describes the GET record data model using go types for mapping.
type Protocol struct {
V3Enabled bool `mapstructure:"v3_enabled"`
Expand Down Expand Up @@ -173,7 +159,7 @@ func GetProtocolsNfsServices(errorHandler *utils.ErrorHandler, r restclient.Rest
}

// CreateProtocolsNfsService Create a NFS Service
func CreateProtocolsNfsService(errorHandler *utils.ErrorHandler, r restclient.RestClient, data ProtocolsNfsServiceResourceDataModelONTAP) (*ProtocolsNfsServiceGetDataModelONTAP, error) {
func CreateProtocolsNfsService(errorHandler *utils.ErrorHandler, r restclient.RestClient, data ProtocolsNfsServiceGetDataModelONTAP, svnUUID string) (*ProtocolsNfsServiceGetDataModelONTAP, error) {
var body map[string]interface{}
if err := mapstructure.Decode(data, &body); err != nil {
return nil, errorHandler.MakeAndReportError("error encoding NFS Service body", fmt.Sprintf("error on encoding protocols/nfs/services body: %s, body: %#v", err, data))
Expand Down Expand Up @@ -202,7 +188,7 @@ func DeleteProtocolsNfsService(errorHandler *utils.ErrorHandler, r restclient.Re
}

// UpdateProtocolsNfsService Update a NFS service
func UpdateProtocolsNfsService(errorHandler *utils.ErrorHandler, r restclient.RestClient, request ProtocolsNfsServiceResourceDataModelONTAP, uuid string) error {
func UpdateProtocolsNfsService(errorHandler *utils.ErrorHandler, r restclient.RestClient, request ProtocolsNfsServiceGetDataModelONTAP, uuid string) error {
var body map[string]interface{}
if err := mapstructure.Decode(request, &body); err != nil {
return errorHandler.MakeAndReportError("error encoding NFS Services body", fmt.Sprintf("error on encoding NFS Services body: %s, body: %#v", err, request))
Expand Down
7 changes: 3 additions & 4 deletions internal/interfaces/protocols_nfs_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,8 @@ func TestCreateProtocolsNfsService(t *testing.T) {
name string
responses []restclient.MockResponse
// args args
requestBody ProtocolsNfsServiceResourceDataModelONTAP
want *ProtocolsNfsServiceGetDataModelONTAP
wantErr bool
want *ProtocolsNfsServiceGetDataModelONTAP
wantErr bool
}{
{name: "test_one_record_1", responses: responses["test_one_record_1"], want: &nfsServiceRecord, wantErr: false},
{name: "test_one_910_record_1", responses: responses["test_one_910_record_1"], want: &record910, wantErr: false},
Expand All @@ -216,7 +215,7 @@ func TestCreateProtocolsNfsService(t *testing.T) {
if err != nil {
panic(err)
}
got, err := CreateProtocolsNfsService(errorHandler, *r, tt.requestBody)
got, err := CreateProtocolsNfsService(errorHandler, *r, nfsServiceRecord, "svmname")
if err != nil {
fmt.Printf("err: %s\n", err)
}
Expand Down
1 change: 1 addition & 0 deletions internal/interfaces/storage_qtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type StorageQtreeResourceBodyDataModelONTAP struct {
SVM svm `mapstructure:"svm"`
UnixPermissions int `mapstructure:"unix_permissions,omitempty"`
Volume qtreeVloume `mapstructure:"volume"`
ID int `mapstructure:"id,omitempty"`
SecurityStyle string `mapstructure:"security_style,omitempty"`
ExportPolicy qtreeExportPolicy `mapstructure:"export_policy,omitempty"`
User qtreeUser `mapstructure:"user,omitempty"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package protocols
import (
"context"
"fmt"

"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
Expand Down Expand Up @@ -161,8 +160,8 @@ func (d *ExportPoliciesDataSource) Read(ctx context.Context, req datasource.Read
CxProfileName: types.String(data.CxProfileName),
Name: types.StringValue(record.Name),
ID: types.Int64Value(int64(record.ID)),
SVMName: types.StringValue(record.Svm),
SVMUUID: types.StringValue(record.SvmUUID),
SVMName: types.StringValue(record.Svm.Name),
SVMUUID: types.StringValue(record.Svm.UUID),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ package protocols
import (
"context"
"fmt"
"github.com/netapp/terraform-provider-netapp-ontap/internal/provider/connection"
"strconv"
"strings"

"github.com/netapp/terraform-provider-netapp-ontap/internal/provider/connection"

"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
Expand Down Expand Up @@ -105,7 +104,7 @@ func (r *ExportPolicyResource) Create(ctx context.Context, req resource.CreateRe
// Read Terraform plan data into the model
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)

var request interfaces.ExportpolicyResourceBodyDataModelONTAP
var request interfaces.ExportpolicyResourceModel
errorHandler := utils.NewErrorHandler(ctx, &resp.Diagnostics)
if resp.Diagnostics.HasError() {
return
Expand Down Expand Up @@ -202,7 +201,7 @@ func (r *ExportPolicyResource) Update(ctx context.Context, req resource.UpdateRe
return
}

var request interfaces.ExportpolicyResourceBodyDataModelONTAP
var request interfaces.ExportpolicyResourceModel
request.Name = data.Name.ValueString()

err = interfaces.UpdateExportPolicy(errorHandler, *client, request, data.ID.ValueString())
Expand Down
Loading

0 comments on commit 41f304d

Please sign in to comment.