diff --git a/internal/provider/client.go b/internal/provider/client.go index a80259a..ef13ca3 100644 --- a/internal/provider/client.go +++ b/internal/provider/client.go @@ -61,6 +61,8 @@ type Device struct { SNMPVersion *string `json:"snmp_version,omitempty"` SNMPPort *int `json:"snmp_port,omitempty"` CheckIntervalSeconds *int `json:"check_interval_seconds,omitempty"` + DeviceRole *string `json:"device_role,omitempty"` + DeviceRoleSource *string `json:"device_role_source,omitempty"` // SNMPv3 fields SNMPv3SecurityLevel *string `json:"snmpv3_security_level,omitempty"` SNMPv3Username *string `json:"snmpv3_username,omitempty"` diff --git a/internal/provider/device_resource.go b/internal/provider/device_resource.go index 08c4057..05f497b 100644 --- a/internal/provider/device_resource.go +++ b/internal/provider/device_resource.go @@ -36,6 +36,8 @@ type DeviceResourceModel struct { SNMPEnabled types.Bool `tfsdk:"snmp_enabled"` SNMPVersion types.String `tfsdk:"snmp_version"` SNMPPort types.Int64 `tfsdk:"snmp_port"` + DeviceRole types.String `tfsdk:"device_role"` + DeviceRoleSource types.String `tfsdk:"device_role_source"` SNMPv3SecurityLevel types.String `tfsdk:"snmpv3_security_level"` SNMPv3Username types.String `tfsdk:"snmpv3_username"` SNMPv3AuthProtocol types.String `tfsdk:"snmpv3_auth_protocol"` @@ -119,6 +121,15 @@ func (r *DeviceResource) Schema(ctx context.Context, req resource.SchemaRequest, Computed: true, Default: int64default.StaticInt64(161), }, + "device_role": schema.StringAttribute{ + Description: "The device type/role. Valid values: server, switch, router, access_point, backhaul, other. Required field.", + Optional: true, + Computed: true, + }, + "device_role_source": schema.StringAttribute{ + Description: "The source of the device role (manual or inferred). Automatically set to 'manual' when device_role is provided.", + Computed: true, + }, "snmpv3_security_level": schema.StringAttribute{ Description: "SNMPv3 security level (noAuthNoPriv, authNoPriv, or authPriv). Only used when snmp_version is '3'.", Optional: true, @@ -205,6 +216,11 @@ func (r *DeviceResource) Create(ctx context.Context, req resource.CreateRequest, device.Description = &desc } + if !data.DeviceRole.IsNull() { + role := data.DeviceRole.ValueString() + device.DeviceRole = &role + } + if !data.MonitoringEnabled.IsNull() { enabled := data.MonitoringEnabled.ValueBool() device.MonitoringEnabled = &enabled @@ -284,6 +300,18 @@ func (r *DeviceResource) Create(ctx context.Context, req resource.CreateRequest, data.Name = types.StringValue(*created.Name) } + if created.DeviceRole != nil { + data.DeviceRole = types.StringValue(*created.DeviceRole) + } else { + data.DeviceRole = types.StringNull() + } + + if created.DeviceRoleSource != nil { + data.DeviceRoleSource = types.StringValue(*created.DeviceRoleSource) + } else { + data.DeviceRoleSource = types.StringNull() + } + if created.MonitoringEnabled != nil { data.MonitoringEnabled = types.BoolValue(*created.MonitoringEnabled) } @@ -340,6 +368,18 @@ func (r *DeviceResource) Read(ctx context.Context, req resource.ReadRequest, res data.Description = types.StringNull() } + if device.DeviceRole != nil { + data.DeviceRole = types.StringValue(*device.DeviceRole) + } else { + data.DeviceRole = types.StringNull() + } + + if device.DeviceRoleSource != nil { + data.DeviceRoleSource = types.StringValue(*device.DeviceRoleSource) + } else { + data.DeviceRoleSource = types.StringNull() + } + if device.MonitoringEnabled != nil { data.MonitoringEnabled = types.BoolValue(*device.MonitoringEnabled) } @@ -428,6 +468,11 @@ func (r *DeviceResource) Update(ctx context.Context, req resource.UpdateRequest, device.Description = &desc } + if !data.DeviceRole.IsNull() { + role := data.DeviceRole.ValueString() + device.DeviceRole = &role + } + if !data.MonitoringEnabled.IsNull() { enabled := data.MonitoringEnabled.ValueBool() device.MonitoringEnabled = &enabled @@ -513,6 +558,16 @@ func (r *DeviceResource) Update(ctx context.Context, req resource.UpdateRequest, if created.Description != nil { data.Description = types.StringValue(*created.Description) } + if created.DeviceRole != nil { + data.DeviceRole = types.StringValue(*created.DeviceRole) + } else { + data.DeviceRole = types.StringNull() + } + if created.DeviceRoleSource != nil { + data.DeviceRoleSource = types.StringValue(*created.DeviceRoleSource) + } else { + data.DeviceRoleSource = types.StringNull() + } if created.MonitoringEnabled != nil { data.MonitoringEnabled = types.BoolValue(*created.MonitoringEnabled) } @@ -552,6 +607,16 @@ func (r *DeviceResource) Update(ctx context.Context, req resource.UpdateRequest, if updated.Description != nil { data.Description = types.StringValue(*updated.Description) } + if updated.DeviceRole != nil { + data.DeviceRole = types.StringValue(*updated.DeviceRole) + } else { + data.DeviceRole = types.StringNull() + } + if updated.DeviceRoleSource != nil { + data.DeviceRoleSource = types.StringValue(*updated.DeviceRoleSource) + } else { + data.DeviceRoleSource = types.StringNull() + } if updated.MonitoringEnabled != nil { data.MonitoringEnabled = types.BoolValue(*updated.MonitoringEnabled) }