diff --git a/docs/resources/device.md b/docs/resources/device.md index 285a874..327e998 100644 --- a/docs/resources/device.md +++ b/docs/resources/device.md @@ -55,6 +55,16 @@ resource "towerops_device" "secure_switch" { } ``` +### Ping/DNS-only Device (no SNMP) + +```terraform +resource "towerops_device" "resolver" { + site_id = towerops_site.example.id + name = "resolver1" + ip_address = "204.110.191.240" +} +``` + ### Minimal Configuration ```terraform @@ -77,7 +87,7 @@ resource "towerops_device" "switch" { - `name` (String) - The name of the device. If not provided, will be auto-discovered from SNMP. - `description` (String) - A description of the device. - `monitoring_enabled` (Boolean) - Whether monitoring is enabled for this device. Default: `true`. -- `snmp_enabled` (Boolean) - Whether SNMP polling is enabled for this device. Default: `true`. +- `snmp_enabled` (Boolean) - Whether SNMP polling is enabled for this device. Default: `false`. - `snmp_version` (String) - The SNMP version to use (`1`, `2c`, or `3`). Default: `"2c"`. - `snmp_port` (Number) - The SNMP port to use. Default: `161`. diff --git a/internal/provider/device_resource.go b/internal/provider/device_resource.go index 9b06679..08c4057 100644 --- a/internal/provider/device_resource.go +++ b/internal/provider/device_resource.go @@ -105,7 +105,7 @@ func (r *DeviceResource) Schema(ctx context.Context, req resource.SchemaRequest, Description: "Whether SNMP polling is enabled for this device.", Optional: true, Computed: true, - Default: booldefault.StaticBool(true), + Default: booldefault.StaticBool(false), }, "snmp_version": schema.StringAttribute{ Description: "The SNMP version to use (1, 2c, or 3).", @@ -215,45 +215,48 @@ func (r *DeviceResource) Create(ctx context.Context, req resource.CreateRequest, device.SNMPEnabled = &enabled } - if !data.SNMPVersion.IsNull() { - version := data.SNMPVersion.ValueString() - device.SNMPVersion = &version - } + // Only send SNMP config when SNMP is enabled + if data.SNMPEnabled.ValueBool() { + if !data.SNMPVersion.IsNull() { + version := data.SNMPVersion.ValueString() + device.SNMPVersion = &version + } - if !data.SNMPPort.IsNull() { - port := int(data.SNMPPort.ValueInt64()) - device.SNMPPort = &port - } + if !data.SNMPPort.IsNull() { + port := int(data.SNMPPort.ValueInt64()) + device.SNMPPort = &port + } - // SNMPv3 fields - if !data.SNMPv3SecurityLevel.IsNull() { - level := data.SNMPv3SecurityLevel.ValueString() - device.SNMPv3SecurityLevel = &level - } + // SNMPv3 fields + if !data.SNMPv3SecurityLevel.IsNull() { + level := data.SNMPv3SecurityLevel.ValueString() + device.SNMPv3SecurityLevel = &level + } - if !data.SNMPv3Username.IsNull() { - username := data.SNMPv3Username.ValueString() - device.SNMPv3Username = &username - } + if !data.SNMPv3Username.IsNull() { + username := data.SNMPv3Username.ValueString() + device.SNMPv3Username = &username + } - if !data.SNMPv3AuthProtocol.IsNull() { - protocol := data.SNMPv3AuthProtocol.ValueString() - device.SNMPv3AuthProtocol = &protocol - } + if !data.SNMPv3AuthProtocol.IsNull() { + protocol := data.SNMPv3AuthProtocol.ValueString() + device.SNMPv3AuthProtocol = &protocol + } - if !data.SNMPv3AuthPassword.IsNull() { - password := data.SNMPv3AuthPassword.ValueString() - device.SNMPv3AuthPassword = &password - } + if !data.SNMPv3AuthPassword.IsNull() { + password := data.SNMPv3AuthPassword.ValueString() + device.SNMPv3AuthPassword = &password + } - if !data.SNMPv3PrivProtocol.IsNull() { - protocol := data.SNMPv3PrivProtocol.ValueString() - device.SNMPv3PrivProtocol = &protocol - } + if !data.SNMPv3PrivProtocol.IsNull() { + protocol := data.SNMPv3PrivProtocol.ValueString() + device.SNMPv3PrivProtocol = &protocol + } - if !data.SNMPv3PrivPassword.IsNull() { - password := data.SNMPv3PrivPassword.ValueString() - device.SNMPv3PrivPassword = &password + if !data.SNMPv3PrivPassword.IsNull() { + password := data.SNMPv3PrivPassword.ValueString() + device.SNMPv3PrivPassword = &password + } } created, err := r.client.CreateDevice(device) @@ -435,45 +438,48 @@ func (r *DeviceResource) Update(ctx context.Context, req resource.UpdateRequest, device.SNMPEnabled = &enabled } - if !data.SNMPVersion.IsNull() { - version := data.SNMPVersion.ValueString() - device.SNMPVersion = &version - } + // Only send SNMP config when SNMP is enabled + if data.SNMPEnabled.ValueBool() { + if !data.SNMPVersion.IsNull() { + version := data.SNMPVersion.ValueString() + device.SNMPVersion = &version + } - if !data.SNMPPort.IsNull() { - port := int(data.SNMPPort.ValueInt64()) - device.SNMPPort = &port - } + if !data.SNMPPort.IsNull() { + port := int(data.SNMPPort.ValueInt64()) + device.SNMPPort = &port + } - // SNMPv3 fields - if !data.SNMPv3SecurityLevel.IsNull() { - level := data.SNMPv3SecurityLevel.ValueString() - device.SNMPv3SecurityLevel = &level - } + // SNMPv3 fields + if !data.SNMPv3SecurityLevel.IsNull() { + level := data.SNMPv3SecurityLevel.ValueString() + device.SNMPv3SecurityLevel = &level + } - if !data.SNMPv3Username.IsNull() { - username := data.SNMPv3Username.ValueString() - device.SNMPv3Username = &username - } + if !data.SNMPv3Username.IsNull() { + username := data.SNMPv3Username.ValueString() + device.SNMPv3Username = &username + } - if !data.SNMPv3AuthProtocol.IsNull() { - protocol := data.SNMPv3AuthProtocol.ValueString() - device.SNMPv3AuthProtocol = &protocol - } + if !data.SNMPv3AuthProtocol.IsNull() { + protocol := data.SNMPv3AuthProtocol.ValueString() + device.SNMPv3AuthProtocol = &protocol + } - if !data.SNMPv3AuthPassword.IsNull() { - password := data.SNMPv3AuthPassword.ValueString() - device.SNMPv3AuthPassword = &password - } + if !data.SNMPv3AuthPassword.IsNull() { + password := data.SNMPv3AuthPassword.ValueString() + device.SNMPv3AuthPassword = &password + } - if !data.SNMPv3PrivProtocol.IsNull() { - protocol := data.SNMPv3PrivProtocol.ValueString() - device.SNMPv3PrivProtocol = &protocol - } + if !data.SNMPv3PrivProtocol.IsNull() { + protocol := data.SNMPv3PrivProtocol.ValueString() + device.SNMPv3PrivProtocol = &protocol + } - if !data.SNMPv3PrivPassword.IsNull() { - password := data.SNMPv3PrivPassword.ValueString() - device.SNMPv3PrivPassword = &password + if !data.SNMPv3PrivPassword.IsNull() { + password := data.SNMPv3PrivPassword.ValueString() + device.SNMPv3PrivPassword = &password + } } updated, err := r.client.UpdateDevice(data.ID.ValueString(), device)