88 "context"
99 "fmt"
1010
11+ "github.com/hashicorp/terraform-plugin-framework-nettypes/cidrtypes"
12+ "github.com/hashicorp/terraform-plugin-framework-nettypes/iptypes"
1113 "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
1214 "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
1315 "github.com/hashicorp/terraform-plugin-framework/diag"
@@ -49,9 +51,9 @@ type switchPortSettingsAddressModel struct {
4951}
5052
5153type switchPortSettingsAddressAddressModel struct {
52- Address types. String `tfsdk:"address"`
53- AddressLotID types.String `tfsdk:"address_lot_id"`
54- VlanID types.Int32 `tfsdk:"vlan_id"`
54+ Address cidrtypes. IPPrefix `tfsdk:"address"`
55+ AddressLotID types.String `tfsdk:"address_lot_id"`
56+ VlanID types.Int32 `tfsdk:"vlan_id"`
5557}
5658
5759type switchPortSettingsBGPPeerModel struct {
@@ -60,7 +62,7 @@ type switchPortSettingsBGPPeerModel struct {
6062}
6163
6264type switchPortSettingsBGPPeerPeerModel struct {
63- Address types. String `tfsdk:"address"`
65+ Address iptypes. IPAddress `tfsdk:"address"`
6466 AllowedExport * switchPortSettingsBGPPeerPeerAllowedExportModel `tfsdk:"allowed_export"`
6567 AllowedImport * switchPortSettingsBGPPeerPeerAllowedImportModel `tfsdk:"allowed_import"`
6668 BGPConfig types.String `tfsdk:"bgp_config"`
@@ -101,13 +103,13 @@ type switchPortSettingsLinkModel struct {
101103}
102104
103105type switchPortSettingsLinkLLDPModel struct {
104- ChassisID types.String `tfsdk:"chassis_id"`
105- Enabled types.Bool `tfsdk:"enabled"`
106- LinkDescription types.String `tfsdk:"link_description"`
107- LinkName types.String `tfsdk:"link_name"`
108- ManagementIP types. String `tfsdk:"management_ip"`
109- SystemDescription types.String `tfsdk:"system_description"`
110- SystemName types.String `tfsdk:"system_name"`
106+ ChassisID types.String `tfsdk:"chassis_id"`
107+ Enabled types.Bool `tfsdk:"enabled"`
108+ LinkDescription types.String `tfsdk:"link_description"`
109+ LinkName types.String `tfsdk:"link_name"`
110+ ManagementIP iptypes. IPAddress `tfsdk:"management_ip"`
111+ SystemDescription types.String `tfsdk:"system_description"`
112+ SystemName types.String `tfsdk:"system_name"`
111113}
112114
113115type switchPortSettingsLinkTxEqModel struct {
@@ -128,10 +130,10 @@ type switchPortSettingsRouteModel struct {
128130}
129131
130132type switchPortSettingsRouteRouteModel struct {
131- Dst types.String `tfsdk:"dst"`
132- GW types. String `tfsdk:"gw"`
133- RIBPriority types.Int32 `tfsdk:"rib_priority"`
134- VID types.Int32 `tfsdk:"vid"`
133+ Dst types.String `tfsdk:"dst"`
134+ GW iptypes. IPAddress `tfsdk:"gw"`
135+ RIBPriority types.Int32 `tfsdk:"rib_priority"`
136+ VID types.Int32 `tfsdk:"vid"`
135137}
136138
137139// NewSwitchPortSettingsResource contructs a Terraform resource.
@@ -198,6 +200,7 @@ func (r *switchPortSettingsResource) Schema(
198200 Attributes : map [string ]schema.Attribute {
199201 "address" : schema.StringAttribute {
200202 Required : true ,
203+ CustomType : cidrtypes.IPPrefixType {},
201204 Description : "IPv4 or IPv6 address, including the subnet mask." ,
202205 },
203206 "address_lot_id" : schema.StringAttribute {
@@ -230,6 +233,7 @@ func (r *switchPortSettingsResource) Schema(
230233 Attributes : map [string ]schema.Attribute {
231234 "address" : schema.StringAttribute {
232235 Required : true ,
236+ CustomType : iptypes.IPAddressType {},
233237 Description : "Address of the host to peer with." ,
234238 },
235239 "allowed_export" : schema.SingleNestedAttribute {
@@ -395,6 +399,7 @@ func (r *switchPortSettingsResource) Schema(
395399 },
396400 "management_ip" : schema.StringAttribute {
397401 Optional : true ,
402+ CustomType : iptypes.IPAddressType {},
398403 Description : "LLDP management IP address." ,
399404 },
400405 "system_description" : schema.StringAttribute {
@@ -498,6 +503,7 @@ func (r *switchPortSettingsResource) Schema(
498503 },
499504 "gw" : schema.StringAttribute {
500505 Required : true ,
506+ CustomType : iptypes.IPAddressType {},
501507 Description : "Gateway IP address for this route." ,
502508 },
503509 "rib_priority" : schema.Int32Attribute {
@@ -827,7 +833,7 @@ func toSwitchPortSettingsModel(
827833 }
828834
829835 addressModel := switchPortSettingsAddressAddressModel {
830- Address : types . StringValue (address .Address .String ()),
836+ Address : cidrtypes . NewIPPrefixValue (address .Address .String ()),
831837 AddressLotID : types .StringValue (string (address .AddressLotId )),
832838 VlanID : func () types.Int32 {
833839 if address .VlanId == nil {
@@ -865,7 +871,7 @@ func toSwitchPortSettingsModel(
865871 }
866872
867873 bgpPeerModel := switchPortSettingsBGPPeerPeerModel {
868- Address : types . StringValue (bgpPeer .Addr ),
874+ Address : iptypes . NewIPAddressValue (bgpPeer .Addr ),
869875 BGPConfig : types .StringValue (string (bgpPeer .BgpConfig )),
870876 ConnectRetry : types .Int64Value (int64 (* bgpPeer .ConnectRetry )),
871877 DelayOpen : types .Int64Value (int64 (* bgpPeer .DelayOpen )),
@@ -1023,11 +1029,11 @@ func toSwitchPortSettingsModel(
10231029 }
10241030 return types .StringValue (link .LldpLinkConfig .LinkName )
10251031 }()
1026- linkModel .LLDP .ManagementIP = func () types. String {
1032+ linkModel .LLDP .ManagementIP = func () iptypes. IPAddress {
10271033 if link .LldpLinkConfig .ManagementIp == "" {
1028- return types . StringNull ()
1034+ return iptypes . NewIPAddressNull ()
10291035 }
1030- return types . StringValue (link .LldpLinkConfig .ManagementIp )
1036+ return iptypes . NewIPAddressValue (link .LldpLinkConfig .ManagementIp )
10311037 }()
10321038 linkModel .LLDP .SystemDescription = func () types.String {
10331039 if link .LldpLinkConfig .SystemDescription == "" {
@@ -1099,7 +1105,7 @@ func toSwitchPortSettingsModel(
10991105
11001106 routeModel := switchPortSettingsRouteRouteModel {
11011107 Dst : types .StringValue (route .Dst .String ()),
1102- GW : types . StringValue (route .Gw ),
1108+ GW : iptypes . NewIPAddressValue (route .Gw ),
11031109 RIBPriority : func () types.Int32 {
11041110 if route .RibPriority != nil {
11051111 return types .Int32Value (int32 (* route .RibPriority ))
0 commit comments