refactor: remove device_role_source field
- Removed DeviceRoleSource field from Device struct and DeviceResourceModel - Updated device_role description to reflect default value "other" - Device role is now optional and defaults to "other" if not specified - Cleaned up all CRUD operations to remove device_role_source handling All device types are now manually selected with "other" as default.
This commit is contained in:
parent
80e800baf4
commit
b922dbda22
5 changed files with 2 additions and 42 deletions
|
|
@ -141,7 +141,6 @@ resource "towerops_check" "wan_ping" {
|
||||||
|
|
||||||
- `hostname` (String) - The hostname to resolve. Required for DNS checks.
|
- `hostname` (String) - The hostname to resolve. Required for DNS checks.
|
||||||
- `record_type` (String) - DNS record type (`A`, `AAAA`, `CNAME`, `MX`, `TXT`, `NS`, `PTR`). Default: `"A"`.
|
- `record_type` (String) - DNS record type (`A`, `AAAA`, `CNAME`, `MX`, `TXT`, `NS`, `PTR`). Default: `"A"`.
|
||||||
- `dns_server` (String) - DNS server to query. Uses system default if not set.
|
|
||||||
- `expected_result` (String) - Expected DNS resolution result.
|
- `expected_result` (String) - Expected DNS resolution result.
|
||||||
|
|
||||||
#### Ping Check Fields (used when `check_type = "ping"`)
|
#### Ping Check Fields (used when `check_type = "ping"`)
|
||||||
|
|
|
||||||
|
|
@ -15,12 +15,11 @@ resource "towerops_check" "radius_port" {
|
||||||
port = 1812
|
port = 1812
|
||||||
}
|
}
|
||||||
|
|
||||||
# DNS resolution check
|
# DNS resolution check (uses device IP as DNS server when device_id is set)
|
||||||
resource "towerops_check" "dns_resolution" {
|
resource "towerops_check" "dns_resolution" {
|
||||||
name = "DNS Resolution"
|
name = "DNS Resolution"
|
||||||
check_type = "dns"
|
check_type = "dns"
|
||||||
hostname = "google.com"
|
hostname = "google.com"
|
||||||
dns_server = "10.0.0.1"
|
|
||||||
record_type = "A"
|
record_type = "A"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,6 @@ type CheckResourceModel struct {
|
||||||
// DNS config
|
// DNS config
|
||||||
Hostname types.String `tfsdk:"hostname"`
|
Hostname types.String `tfsdk:"hostname"`
|
||||||
RecordType types.String `tfsdk:"record_type"`
|
RecordType types.String `tfsdk:"record_type"`
|
||||||
DNSServer types.String `tfsdk:"dns_server"`
|
|
||||||
ExpectedResult types.String `tfsdk:"expected_result"`
|
ExpectedResult types.String `tfsdk:"expected_result"`
|
||||||
|
|
||||||
// Ping config
|
// Ping config
|
||||||
|
|
@ -205,10 +204,6 @@ func (r *CheckResource) Schema(ctx context.Context, req resource.SchemaRequest,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
Default: stringdefault.StaticString("A"),
|
Default: stringdefault.StaticString("A"),
|
||||||
},
|
},
|
||||||
"dns_server": schema.StringAttribute{
|
|
||||||
Description: "DNS server to query. Uses system default if not set.",
|
|
||||||
Optional: true,
|
|
||||||
},
|
|
||||||
"expected_result": schema.StringAttribute{
|
"expected_result": schema.StringAttribute{
|
||||||
Description: "Expected DNS resolution result.",
|
Description: "Expected DNS resolution result.",
|
||||||
Optional: true,
|
Optional: true,
|
||||||
|
|
@ -490,9 +485,6 @@ func buildConfig(data CheckResourceModel) map[string]any {
|
||||||
if !data.RecordType.IsNull() {
|
if !data.RecordType.IsNull() {
|
||||||
config["record_type"] = data.RecordType.ValueString()
|
config["record_type"] = data.RecordType.ValueString()
|
||||||
}
|
}
|
||||||
if !data.DNSServer.IsNull() {
|
|
||||||
config["server"] = data.DNSServer.ValueString()
|
|
||||||
}
|
|
||||||
if !data.ExpectedResult.IsNull() {
|
if !data.ExpectedResult.IsNull() {
|
||||||
config["expected"] = data.ExpectedResult.ValueString()
|
config["expected"] = data.ExpectedResult.ValueString()
|
||||||
}
|
}
|
||||||
|
|
@ -624,9 +616,6 @@ func unpackConfig(config map[string]any, checkType string, data *CheckResourceMo
|
||||||
if v, ok := config["record_type"].(string); ok {
|
if v, ok := config["record_type"].(string); ok {
|
||||||
data.RecordType = types.StringValue(v)
|
data.RecordType = types.StringValue(v)
|
||||||
}
|
}
|
||||||
if v, ok := config["server"].(string); ok {
|
|
||||||
data.DNSServer = types.StringValue(v)
|
|
||||||
}
|
|
||||||
if v, ok := config["expected"].(string); ok {
|
if v, ok := config["expected"].(string); ok {
|
||||||
data.ExpectedResult = types.StringValue(v)
|
data.ExpectedResult = types.StringValue(v)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,6 @@ type Device struct {
|
||||||
SNMPPort *int `json:"snmp_port,omitempty"`
|
SNMPPort *int `json:"snmp_port,omitempty"`
|
||||||
CheckIntervalSeconds *int `json:"check_interval_seconds,omitempty"`
|
CheckIntervalSeconds *int `json:"check_interval_seconds,omitempty"`
|
||||||
DeviceRole *string `json:"device_role,omitempty"`
|
DeviceRole *string `json:"device_role,omitempty"`
|
||||||
DeviceRoleSource *string `json:"device_role_source,omitempty"`
|
|
||||||
// SNMPv3 fields
|
// SNMPv3 fields
|
||||||
SNMPv3SecurityLevel *string `json:"snmpv3_security_level,omitempty"`
|
SNMPv3SecurityLevel *string `json:"snmpv3_security_level,omitempty"`
|
||||||
SNMPv3Username *string `json:"snmpv3_username,omitempty"`
|
SNMPv3Username *string `json:"snmpv3_username,omitempty"`
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,6 @@ type DeviceResourceModel struct {
|
||||||
SNMPVersion types.String `tfsdk:"snmp_version"`
|
SNMPVersion types.String `tfsdk:"snmp_version"`
|
||||||
SNMPPort types.Int64 `tfsdk:"snmp_port"`
|
SNMPPort types.Int64 `tfsdk:"snmp_port"`
|
||||||
DeviceRole types.String `tfsdk:"device_role"`
|
DeviceRole types.String `tfsdk:"device_role"`
|
||||||
DeviceRoleSource types.String `tfsdk:"device_role_source"`
|
|
||||||
SNMPv3SecurityLevel types.String `tfsdk:"snmpv3_security_level"`
|
SNMPv3SecurityLevel types.String `tfsdk:"snmpv3_security_level"`
|
||||||
SNMPv3Username types.String `tfsdk:"snmpv3_username"`
|
SNMPv3Username types.String `tfsdk:"snmpv3_username"`
|
||||||
SNMPv3AuthProtocol types.String `tfsdk:"snmpv3_auth_protocol"`
|
SNMPv3AuthProtocol types.String `tfsdk:"snmpv3_auth_protocol"`
|
||||||
|
|
@ -122,14 +121,10 @@ func (r *DeviceResource) Schema(ctx context.Context, req resource.SchemaRequest,
|
||||||
Default: int64default.StaticInt64(161),
|
Default: int64default.StaticInt64(161),
|
||||||
},
|
},
|
||||||
"device_role": schema.StringAttribute{
|
"device_role": schema.StringAttribute{
|
||||||
Description: "The device type/role. Valid values: server, switch, router, access_point, backhaul, other. Required field.",
|
Description: "The device type/role. Valid values: server, switch, router, access_point, backhaul, other. Defaults to 'other' if not specified.",
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Computed: 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{
|
"snmpv3_security_level": schema.StringAttribute{
|
||||||
Description: "SNMPv3 security level (noAuthNoPriv, authNoPriv, or authPriv). Only used when snmp_version is '3'.",
|
Description: "SNMPv3 security level (noAuthNoPriv, authNoPriv, or authPriv). Only used when snmp_version is '3'.",
|
||||||
Optional: true,
|
Optional: true,
|
||||||
|
|
@ -306,11 +301,6 @@ func (r *DeviceResource) Create(ctx context.Context, req resource.CreateRequest,
|
||||||
data.DeviceRole = types.StringNull()
|
data.DeviceRole = types.StringNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
if created.DeviceRoleSource != nil {
|
|
||||||
data.DeviceRoleSource = types.StringValue(*created.DeviceRoleSource)
|
|
||||||
} else {
|
|
||||||
data.DeviceRoleSource = types.StringNull()
|
|
||||||
}
|
|
||||||
|
|
||||||
if created.MonitoringEnabled != nil {
|
if created.MonitoringEnabled != nil {
|
||||||
data.MonitoringEnabled = types.BoolValue(*created.MonitoringEnabled)
|
data.MonitoringEnabled = types.BoolValue(*created.MonitoringEnabled)
|
||||||
|
|
@ -374,12 +364,6 @@ func (r *DeviceResource) Read(ctx context.Context, req resource.ReadRequest, res
|
||||||
data.DeviceRole = types.StringNull()
|
data.DeviceRole = types.StringNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
if device.DeviceRoleSource != nil {
|
|
||||||
data.DeviceRoleSource = types.StringValue(*device.DeviceRoleSource)
|
|
||||||
} else {
|
|
||||||
data.DeviceRoleSource = types.StringNull()
|
|
||||||
}
|
|
||||||
|
|
||||||
if device.MonitoringEnabled != nil {
|
if device.MonitoringEnabled != nil {
|
||||||
data.MonitoringEnabled = types.BoolValue(*device.MonitoringEnabled)
|
data.MonitoringEnabled = types.BoolValue(*device.MonitoringEnabled)
|
||||||
}
|
}
|
||||||
|
|
@ -563,11 +547,6 @@ func (r *DeviceResource) Update(ctx context.Context, req resource.UpdateRequest,
|
||||||
} else {
|
} else {
|
||||||
data.DeviceRole = types.StringNull()
|
data.DeviceRole = types.StringNull()
|
||||||
}
|
}
|
||||||
if created.DeviceRoleSource != nil {
|
|
||||||
data.DeviceRoleSource = types.StringValue(*created.DeviceRoleSource)
|
|
||||||
} else {
|
|
||||||
data.DeviceRoleSource = types.StringNull()
|
|
||||||
}
|
|
||||||
if created.MonitoringEnabled != nil {
|
if created.MonitoringEnabled != nil {
|
||||||
data.MonitoringEnabled = types.BoolValue(*created.MonitoringEnabled)
|
data.MonitoringEnabled = types.BoolValue(*created.MonitoringEnabled)
|
||||||
}
|
}
|
||||||
|
|
@ -612,11 +591,6 @@ func (r *DeviceResource) Update(ctx context.Context, req resource.UpdateRequest,
|
||||||
} else {
|
} else {
|
||||||
data.DeviceRole = types.StringNull()
|
data.DeviceRole = types.StringNull()
|
||||||
}
|
}
|
||||||
if updated.DeviceRoleSource != nil {
|
|
||||||
data.DeviceRoleSource = types.StringValue(*updated.DeviceRoleSource)
|
|
||||||
} else {
|
|
||||||
data.DeviceRoleSource = types.StringNull()
|
|
||||||
}
|
|
||||||
if updated.MonitoringEnabled != nil {
|
if updated.MonitoringEnabled != nil {
|
||||||
data.MonitoringEnabled = types.BoolValue(*updated.MonitoringEnabled)
|
data.MonitoringEnabled = types.BoolValue(*updated.MonitoringEnabled)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue