Skip to content

Commit

Permalink
feat: add service_policy parameter to ip_interface(s) data source
Browse files Browse the repository at this point in the history
Signed-off-by: Achim Christ <[email protected]>
  • Loading branch information
acch committed Oct 31, 2024
1 parent f36d4c1 commit 67ade07
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 11 deletions.
45 changes: 36 additions & 9 deletions internal/interfaces/networking_ip_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import (

// IPInterfaceGetDataModelONTAP describes the GET record data model using go types for mapping.
type IPInterfaceGetDataModelONTAP struct {
Name string `mapstructure:"name"`
Scope string `mapstructure:"scope"`
SVM IPInterfaceSvmName `mapstructure:"svm"`
UUID string `mapstructure:"uuid"`
IP IPInterfaceGetIP `mapstructure:"ip"`
Location IPInterfaceResourceLocation `mapstructure:"location"`
IP IPInterfaceGetIP `mapstructure:"ip"`
Location IPInterfaceResourceLocation `mapstructure:"location"`
Name string `mapstructure:"name"`
Scope string `mapstructure:"scope"`
ServicePolicy IPInterfaceServicePolicy `mapstructure:"service_policy"`
SVM IPInterfaceSvmName `mapstructure:"svm"`
UUID string `mapstructure:"uuid"`
}

// IPInterfaceGetIP describes the GET record data for IP.
Expand Down Expand Up @@ -61,6 +62,11 @@ type IPInterfaceResourceHomePort struct {
Node IPInterfaceResourceHomeNode `mapstructure:"node"`
}

// IPInterfaceServicePolicy is the body data model for the service_policy field
type IPInterfaceServicePolicy struct {
Name string `mapstructure:"name"`
}

// IPInterfaceDataSourceFilterModel describes filter model.
type IPInterfaceDataSourceFilterModel struct {
Name string `tfsdk:"name"`
Expand All @@ -78,7 +84,14 @@ func GetIPInterface(errorHandler *utils.ErrorHandler, r restclient.RestClient, i
// query.Set("svm.name", svmName)
// query.Set("scope", "svm")
// }
query.Fields([]string{"name", "svm.name", "ip", "scope", "location"})
query.Fields([]string{
"name",
"svm.name",
"ip",
"scope",
"location",
"service_policy",
})
statusCode, response, err := r.GetNilOrOneRecord(api, query, nil)
if err == nil && response == nil {
err = fmt.Errorf("no response for GET %s", api)
Expand Down Expand Up @@ -107,7 +120,14 @@ func GetIPInterfaceByName(errorHandler *utils.ErrorHandler, r restclient.RestCli
query.Set("svm.name", svmName)
query.Set("scope", "svm")
}
query.Fields([]string{"name", "svm.name", "ip", "scope", "location"})
query.Fields([]string{
"name",
"svm.name",
"ip",
"scope",
"location",
"service_policy",
})
statusCode, response, err := r.GetNilOrOneRecord(api, query, nil)
if err == nil && response == nil {
err = fmt.Errorf("no response for GET %s", api)
Expand All @@ -129,7 +149,14 @@ func GetIPInterfaceByName(errorHandler *utils.ErrorHandler, r restclient.RestCli
func GetListIPInterfaces(errorHandler *utils.ErrorHandler, r restclient.RestClient, filter *IPInterfaceDataSourceFilterModel) ([]IPInterfaceGetDataModelONTAP, error) {
api := "network/ip/interfaces"
query := r.NewQuery()
query.Fields([]string{"name", "svm.name", "ip", "scope", "location"})
query.Fields([]string{
"name",
"svm.name",
"ip",
"scope",
"location",
"service_policy",
})

if filter != nil {
if filter.Name != "" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package networking
import (
"context"
"fmt"
"github.com/netapp/terraform-provider-netapp-ontap/internal/provider/connection"
"strconv"

"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/netapp/terraform-provider-netapp-ontap/internal/interfaces"
"github.com/netapp/terraform-provider-netapp-ontap/internal/provider/connection"
"github.com/netapp/terraform-provider-netapp-ontap/internal/utils"
)

Expand Down Expand Up @@ -39,6 +39,7 @@ type IPInterfaceDataSourceModel struct {
Scope types.String `tfsdk:"scope"`
IP *IPDataSourceModel `tfsdk:"ip"`
Location *LocationDataSourceModel `tfsdk:"location"`
ServicePolicy types.String `tfsdk:"service_policy"`
}

// IPDataSourceModel describes the data source model for IP address and mask.
Expand Down Expand Up @@ -107,6 +108,10 @@ func (d *IPInterfaceDataSource) Schema(ctx context.Context, req datasource.Schem
},
Computed: true,
},
"service_policy": schema.StringAttribute{
Computed: true,
MarkdownDescription: "IPInterface service policy",
},
},
}
}
Expand Down Expand Up @@ -172,6 +177,7 @@ func (d *IPInterfaceDataSource) Read(ctx context.Context, req datasource.ReadReq
HomeNode: types.StringValue(restInfo.Location.HomeNode.Name),
HomePort: types.StringValue(restInfo.Location.HomePort.Name),
}
data.ServicePolicy = types.StringValue(restInfo.ServicePolicy.Name)

// Write logs using the tflog package
// Documentation: https://terraform.io/plugin/log
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package networking
import (
"context"
"fmt"
"github.com/netapp/terraform-provider-netapp-ontap/internal/provider/connection"
"strconv"

"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/netapp/terraform-provider-netapp-ontap/internal/interfaces"
"github.com/netapp/terraform-provider-netapp-ontap/internal/provider/connection"
"github.com/netapp/terraform-provider-netapp-ontap/internal/utils"
)

Expand Down Expand Up @@ -123,6 +123,10 @@ func (d *IPInterfacesDataSource) Schema(ctx context.Context, req datasource.Sche
},
Computed: true,
},
"service_policy": schema.StringAttribute{
Computed: true,
MarkdownDescription: "IPInterface service policy",
},
},
},
Computed: true,
Expand Down Expand Up @@ -189,6 +193,7 @@ func (d *IPInterfacesDataSource) Read(ctx context.Context, req datasource.ReadRe
Name: types.StringValue(record.Name),
Scope: types.StringValue(record.Scope),
SVMName: types.StringValue(record.SVM.Name),
ServicePolicy: types.StringValue(record.ServicePolicy.Name),
}
intNetmask, err := strconv.Atoi(record.IP.Netmask)
if err != nil {
Expand Down

0 comments on commit 67ade07

Please sign in to comment.