Skip to content

Commit

Permalink
feat: add service_policy parameter to ip_interface resource
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 67ade07 commit 1de03df
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
7 changes: 4 additions & 3 deletions examples/resources/netapp-ontap_ip_interface/resource.tf
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
resource "netapp-ontap_networking_ip_interface" "ip_interface" {
# required to know which system to interface with
cx_profile_name = "cluster4"
name = "testme"
svm_name = "ansibleSVM"
name = "testme"
svm_name = "ansibleSVM"
ip = {
address = "10.10.10.10"
netmask = 20
}
}
location = {
home_port = "e0c"
home_node = "ontap_cluster_1-01"
}
service_policy = "default-management"
}
9 changes: 5 additions & 4 deletions internal/interfaces/networking_ip_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ type IPInterfaceGetIP struct {

// IPInterfaceResourceBodyDataModelONTAP describes the body data model using go types for mapping.
type IPInterfaceResourceBodyDataModelONTAP struct {
Name string `mapstructure:"name"`
SVM IPInterfaceSvmName `mapstructure:"svm,omitempty"` // API errors if body contains svm name when updating. can not use universal 'svm struct'
IP IPInterfaceResourceIP `mapstructure:"ip"`
Location IPInterfaceResourceLocation `mapstructure:"location"`
IP IPInterfaceResourceIP `mapstructure:"ip"`
Location IPInterfaceResourceLocation `mapstructure:"location"`
Name string `mapstructure:"name"`
ServicePolicy IPInterfaceServicePolicy `mapstructure:"service_policy"`
SVM IPInterfaceSvmName `mapstructure:"svm,omitempty"` // API errors if body contains svm name when updating. can not use universal 'svm struct'
}

// IPInterfaceSvmName describes the svm name specifcally for network ip interface.
Expand Down
21 changes: 20 additions & 1 deletion internal/provider/networking/networking_ip_interface_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ package networking
import (
"context"
"fmt"
"github.com/netapp/terraform-provider-netapp-ontap/internal/provider/connection"
"strconv"
"strings"

"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"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 @@ -55,6 +56,7 @@ type IPInterfaceResourceModel struct {
SVMName types.String `tfsdk:"svm_name"`
IP *IPInterfaceResourceIP `tfsdk:"ip"`
Location *IPInterfaceResourceLocation `tfsdk:"location"`
ServicePolicy types.String `tfsdk:"service_policy"`
UUID types.String `tfsdk:"id"`
}

Expand Down Expand Up @@ -111,6 +113,18 @@ func (r *IPInterfaceResource) Schema(ctx context.Context, req resource.SchemaReq
},
Required: true,
},
"service_policy": schema.StringAttribute{
MarkdownDescription: "IPInterface service policy",
Optional: true,
Computed: true,
/*
* Default values:
* "default-data-files" if scope is svm
* "default-management" if scope is cluster and IPspace is not Cluster (not yet implemented)
* "default-cluster" if scope is cluster and IPspace is Cluster (not yet implemented)
*/
Default: stringdefault.StaticString("default-data-files"),
},
"id": schema.StringAttribute{
MarkdownDescription: "IPInterface UUID",
Computed: true,
Expand Down Expand Up @@ -192,6 +206,9 @@ func (r *IPInterfaceResource) Read(ctx context.Context, req resource.ReadRequest
}
ip.Netmask = types.Int64Value(int64(intValue))
data.IP = &ip

data.ServicePolicy = types.StringValue(restInfo.ServicePolicy.Name)

// Write logs using the tflog package
// Documentation: https://terraform.io/plugin/log
tflog.Debug(ctx, fmt.Sprintf("read a resource: %#v", data))
Expand Down Expand Up @@ -228,6 +245,7 @@ func (r *IPInterfaceResource) Create(ctx context.Context, req resource.CreateReq
body.Location.HomeNode = interfaces.IPInterfaceResourceHomeNode{
Name: data.Location.HomeNode.ValueString(),
}
body.ServicePolicy.Name = data.ServicePolicy.ValueString()

client, err := connection.GetRestClient(errorHandler, r.config, data.CxProfileName)
if err != nil {
Expand Down Expand Up @@ -274,6 +292,7 @@ func (r *IPInterfaceResource) Update(ctx context.Context, req resource.UpdateReq
body.Location.HomeNode = interfaces.IPInterfaceResourceHomeNode{
Name: data.Location.HomeNode.ValueString(),
}
body.ServicePolicy.Name = data.ServicePolicy.ValueString()

client, err := connection.GetRestClient(errorHandler, r.config, data.CxProfileName)
if err != nil {
Expand Down

0 comments on commit 1de03df

Please sign in to comment.