diff --git a/internal/interfaces/svm.go b/internal/interfaces/svm.go index f40a14fd..e1fccc5c 100644 --- a/internal/interfaces/svm.go +++ b/internal/interfaces/svm.go @@ -129,10 +129,10 @@ func GetSvmByNameIgnoreNotFound(errorHandler *utils.ErrorHandler, r restclient.R } // GetSvmByNameDataSource to get data source svm info -func GetSvmByNameDataSource(errorHandler *utils.ErrorHandler, r restclient.RestClient, name string) (*SvmGetDataSourceModel, error) { +func GetSvmByNameDataSource(errorHandler *utils.ErrorHandler, r restclient.RestClient, name string, version versionModelONTAP) (*SvmGetDataSourceModel, error) { api := "svm/svms" query := r.NewQuery() - query.Fields([]string{ + fields := []string{ "name", "ipspace", "snapshot_policy", @@ -141,9 +141,13 @@ func GetSvmByNameDataSource(errorHandler *utils.ErrorHandler, r restclient.RestC "language", "max_volumes", "aggregates", - "storage.limit", - }) + } + if version.Generation >= 9 && version.Major >= 13 { + fields = append(fields, "storage.limit") + } + query.Fields(fields) query.Add("name", name) + statusCode, response, err := r.GetNilOrOneRecord(api, query, nil) if err == nil && response == nil { err = fmt.Errorf("no response for GET %s", api) @@ -161,10 +165,10 @@ func GetSvmByNameDataSource(errorHandler *utils.ErrorHandler, r restclient.RestC } // GetSvmsByName to get data source list svm info -func GetSvmsByName(errorHandler *utils.ErrorHandler, r restclient.RestClient, filter *SvmDataSourceFilterModel) ([]SvmGetDataSourceModel, error) { +func GetSvmsByName(errorHandler *utils.ErrorHandler, r restclient.RestClient, filter *SvmDataSourceFilterModel, version versionModelONTAP) ([]SvmGetDataSourceModel, error) { api := "svm/svms" query := r.NewQuery() - query.Fields([]string{ + fields := []string{ "name", "ipspace", "snapshot_policy", @@ -173,8 +177,11 @@ func GetSvmsByName(errorHandler *utils.ErrorHandler, r restclient.RestClient, fi "language", "max_volumes", "aggregates", - "storage.limit", - }) + } + if version.Generation >= 9 && version.Major >= 13 { + fields = append(fields, "storage.limit") + } + query.Fields(fields) if filter != nil { var filterMap map[string]interface{} diff --git a/internal/provider/svm/svm_data_source.go b/internal/provider/svm/svm_data_source.go index 265157dc..85a02d31 100644 --- a/internal/provider/svm/svm_data_source.go +++ b/internal/provider/svm/svm_data_source.go @@ -155,7 +155,17 @@ func (d *SvmDataSource) Read(ctx context.Context, req datasource.ReadRequest, re return } - restInfo, err := interfaces.GetSvmByNameDataSource(errorHandler, *client, data.Name.ValueString()) + cluster, err := interfaces.GetCluster(errorHandler, *client) + if err != nil { + // error reporting done inside GetCluster + return + } + if cluster == nil { + errorHandler.MakeAndReportError("No cluster found", "cluster not found") + return + } + + restInfo, err := interfaces.GetSvmByNameDataSource(errorHandler, *client, data.Name.ValueString(), cluster.Version) if err != nil { // error reporting done inside GetSvm return diff --git a/internal/provider/svm/svm_resource.go b/internal/provider/svm/svm_resource.go index b4947403..1f44e440 100644 --- a/internal/provider/svm/svm_resource.go +++ b/internal/provider/svm/svm_resource.go @@ -265,12 +265,23 @@ func (r *SvmResource) Read(ctx context.Context, req resource.ReadRequest, resp * // error reporting done inside NewClient return } + + cluster, err := interfaces.GetCluster(errorHandler, *client) + if err != nil { + // error reporting done inside GetCluster + return + } + if cluster == nil { + errorHandler.MakeAndReportError("No cluster found", "cluster not found") + return + } + tflog.Debug(ctx, fmt.Sprintf("read a svm resource: %#v", data)) var svm *interfaces.SvmGetDataSourceModel if data.ID.ValueString() != "" { svm, err = interfaces.GetSvm(errorHandler, *client, data.ID.ValueString()) } else { - svm, err = interfaces.GetSvmByNameDataSource(errorHandler, *client, data.Name.ValueString()) + svm, err = interfaces.GetSvmByNameDataSource(errorHandler, *client, data.Name.ValueString(), cluster.Version) } if err != nil { return diff --git a/internal/provider/svm/svms_data_source.go b/internal/provider/svm/svms_data_source.go index 30323e8c..8dd6c0fc 100644 --- a/internal/provider/svm/svms_data_source.go +++ b/internal/provider/svm/svms_data_source.go @@ -165,7 +165,18 @@ func (d *SvmsDataSource) Read(ctx context.Context, req datasource.ReadRequest, r Name: data.Filter.Name.ValueString(), } } - restInfo, err := interfaces.GetSvmsByName(errorHandler, *client, filter) + + cluster, err := interfaces.GetCluster(errorHandler, *client) + if err != nil { + // error reporting done inside GetCluster + return + } + if cluster == nil { + errorHandler.MakeAndReportError("No cluster found", "cluster not found") + return + } + + restInfo, err := interfaces.GetSvmsByName(errorHandler, *client, filter, cluster.Version) if err != nil { // error reporting done inside GetSvms return