Merge pull request #1 from towerops-app/snmp-opt-in
make snmp opt-in for terraform provider devices
This commit is contained in:
commit
632a3ae4df
2 changed files with 82 additions and 66 deletions
|
|
@ -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
|
### Minimal Configuration
|
||||||
|
|
||||||
```terraform
|
```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.
|
- `name` (String) - The name of the device. If not provided, will be auto-discovered from SNMP.
|
||||||
- `description` (String) - A description of the device.
|
- `description` (String) - A description of the device.
|
||||||
- `monitoring_enabled` (Boolean) - Whether monitoring is enabled for this device. Default: `true`.
|
- `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_version` (String) - The SNMP version to use (`1`, `2c`, or `3`). Default: `"2c"`.
|
||||||
- `snmp_port` (Number) - The SNMP port to use. Default: `161`.
|
- `snmp_port` (Number) - The SNMP port to use. Default: `161`.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ func (r *DeviceResource) Schema(ctx context.Context, req resource.SchemaRequest,
|
||||||
Description: "Whether SNMP polling is enabled for this device.",
|
Description: "Whether SNMP polling is enabled for this device.",
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
Default: booldefault.StaticBool(true),
|
Default: booldefault.StaticBool(false),
|
||||||
},
|
},
|
||||||
"snmp_version": schema.StringAttribute{
|
"snmp_version": schema.StringAttribute{
|
||||||
Description: "The SNMP version to use (1, 2c, or 3).",
|
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
|
device.SNMPEnabled = &enabled
|
||||||
}
|
}
|
||||||
|
|
||||||
if !data.SNMPVersion.IsNull() {
|
// Only send SNMP config when SNMP is enabled
|
||||||
version := data.SNMPVersion.ValueString()
|
if data.SNMPEnabled.ValueBool() {
|
||||||
device.SNMPVersion = &version
|
if !data.SNMPVersion.IsNull() {
|
||||||
}
|
version := data.SNMPVersion.ValueString()
|
||||||
|
device.SNMPVersion = &version
|
||||||
|
}
|
||||||
|
|
||||||
if !data.SNMPPort.IsNull() {
|
if !data.SNMPPort.IsNull() {
|
||||||
port := int(data.SNMPPort.ValueInt64())
|
port := int(data.SNMPPort.ValueInt64())
|
||||||
device.SNMPPort = &port
|
device.SNMPPort = &port
|
||||||
}
|
}
|
||||||
|
|
||||||
// SNMPv3 fields
|
// SNMPv3 fields
|
||||||
if !data.SNMPv3SecurityLevel.IsNull() {
|
if !data.SNMPv3SecurityLevel.IsNull() {
|
||||||
level := data.SNMPv3SecurityLevel.ValueString()
|
level := data.SNMPv3SecurityLevel.ValueString()
|
||||||
device.SNMPv3SecurityLevel = &level
|
device.SNMPv3SecurityLevel = &level
|
||||||
}
|
}
|
||||||
|
|
||||||
if !data.SNMPv3Username.IsNull() {
|
if !data.SNMPv3Username.IsNull() {
|
||||||
username := data.SNMPv3Username.ValueString()
|
username := data.SNMPv3Username.ValueString()
|
||||||
device.SNMPv3Username = &username
|
device.SNMPv3Username = &username
|
||||||
}
|
}
|
||||||
|
|
||||||
if !data.SNMPv3AuthProtocol.IsNull() {
|
if !data.SNMPv3AuthProtocol.IsNull() {
|
||||||
protocol := data.SNMPv3AuthProtocol.ValueString()
|
protocol := data.SNMPv3AuthProtocol.ValueString()
|
||||||
device.SNMPv3AuthProtocol = &protocol
|
device.SNMPv3AuthProtocol = &protocol
|
||||||
}
|
}
|
||||||
|
|
||||||
if !data.SNMPv3AuthPassword.IsNull() {
|
if !data.SNMPv3AuthPassword.IsNull() {
|
||||||
password := data.SNMPv3AuthPassword.ValueString()
|
password := data.SNMPv3AuthPassword.ValueString()
|
||||||
device.SNMPv3AuthPassword = &password
|
device.SNMPv3AuthPassword = &password
|
||||||
}
|
}
|
||||||
|
|
||||||
if !data.SNMPv3PrivProtocol.IsNull() {
|
if !data.SNMPv3PrivProtocol.IsNull() {
|
||||||
protocol := data.SNMPv3PrivProtocol.ValueString()
|
protocol := data.SNMPv3PrivProtocol.ValueString()
|
||||||
device.SNMPv3PrivProtocol = &protocol
|
device.SNMPv3PrivProtocol = &protocol
|
||||||
}
|
}
|
||||||
|
|
||||||
if !data.SNMPv3PrivPassword.IsNull() {
|
if !data.SNMPv3PrivPassword.IsNull() {
|
||||||
password := data.SNMPv3PrivPassword.ValueString()
|
password := data.SNMPv3PrivPassword.ValueString()
|
||||||
device.SNMPv3PrivPassword = &password
|
device.SNMPv3PrivPassword = &password
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
created, err := r.client.CreateDevice(device)
|
created, err := r.client.CreateDevice(device)
|
||||||
|
|
@ -435,45 +438,48 @@ func (r *DeviceResource) Update(ctx context.Context, req resource.UpdateRequest,
|
||||||
device.SNMPEnabled = &enabled
|
device.SNMPEnabled = &enabled
|
||||||
}
|
}
|
||||||
|
|
||||||
if !data.SNMPVersion.IsNull() {
|
// Only send SNMP config when SNMP is enabled
|
||||||
version := data.SNMPVersion.ValueString()
|
if data.SNMPEnabled.ValueBool() {
|
||||||
device.SNMPVersion = &version
|
if !data.SNMPVersion.IsNull() {
|
||||||
}
|
version := data.SNMPVersion.ValueString()
|
||||||
|
device.SNMPVersion = &version
|
||||||
|
}
|
||||||
|
|
||||||
if !data.SNMPPort.IsNull() {
|
if !data.SNMPPort.IsNull() {
|
||||||
port := int(data.SNMPPort.ValueInt64())
|
port := int(data.SNMPPort.ValueInt64())
|
||||||
device.SNMPPort = &port
|
device.SNMPPort = &port
|
||||||
}
|
}
|
||||||
|
|
||||||
// SNMPv3 fields
|
// SNMPv3 fields
|
||||||
if !data.SNMPv3SecurityLevel.IsNull() {
|
if !data.SNMPv3SecurityLevel.IsNull() {
|
||||||
level := data.SNMPv3SecurityLevel.ValueString()
|
level := data.SNMPv3SecurityLevel.ValueString()
|
||||||
device.SNMPv3SecurityLevel = &level
|
device.SNMPv3SecurityLevel = &level
|
||||||
}
|
}
|
||||||
|
|
||||||
if !data.SNMPv3Username.IsNull() {
|
if !data.SNMPv3Username.IsNull() {
|
||||||
username := data.SNMPv3Username.ValueString()
|
username := data.SNMPv3Username.ValueString()
|
||||||
device.SNMPv3Username = &username
|
device.SNMPv3Username = &username
|
||||||
}
|
}
|
||||||
|
|
||||||
if !data.SNMPv3AuthProtocol.IsNull() {
|
if !data.SNMPv3AuthProtocol.IsNull() {
|
||||||
protocol := data.SNMPv3AuthProtocol.ValueString()
|
protocol := data.SNMPv3AuthProtocol.ValueString()
|
||||||
device.SNMPv3AuthProtocol = &protocol
|
device.SNMPv3AuthProtocol = &protocol
|
||||||
}
|
}
|
||||||
|
|
||||||
if !data.SNMPv3AuthPassword.IsNull() {
|
if !data.SNMPv3AuthPassword.IsNull() {
|
||||||
password := data.SNMPv3AuthPassword.ValueString()
|
password := data.SNMPv3AuthPassword.ValueString()
|
||||||
device.SNMPv3AuthPassword = &password
|
device.SNMPv3AuthPassword = &password
|
||||||
}
|
}
|
||||||
|
|
||||||
if !data.SNMPv3PrivProtocol.IsNull() {
|
if !data.SNMPv3PrivProtocol.IsNull() {
|
||||||
protocol := data.SNMPv3PrivProtocol.ValueString()
|
protocol := data.SNMPv3PrivProtocol.ValueString()
|
||||||
device.SNMPv3PrivProtocol = &protocol
|
device.SNMPv3PrivProtocol = &protocol
|
||||||
}
|
}
|
||||||
|
|
||||||
if !data.SNMPv3PrivPassword.IsNull() {
|
if !data.SNMPv3PrivPassword.IsNull() {
|
||||||
password := data.SNMPv3PrivPassword.ValueString()
|
password := data.SNMPv3PrivPassword.ValueString()
|
||||||
device.SNMPv3PrivPassword = &password
|
device.SNMPv3PrivPassword = &password
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updated, err := r.client.UpdateDevice(data.ID.ValueString(), device)
|
updated, err := r.client.UpdateDevice(data.ID.ValueString(), device)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue