Plenty of writes now works and an expanded example exists in the terraform directory
This commit is contained in:
1 parent
a6f1019175
commit
fb8d468943
15 files changed
+1344
-74
No files matched your search
+51
-14
@@ -1,17 +1,54 @@
|
||||
# All 13 read-only extractors are now ported as data sources -- see
|
||||
# ~/code/experiments/hpe/terraform-provider-hpe1810/internal/provider/data_source_*.go
|
||||
# Eventually resource "hpe1810_locator" once actions/locator.py is ported.
|
||||
#
|
||||
# First write resource: the locator LED. Singleton; Delete resets it to
|
||||
# Disable (see resource_locator.go for why that's safe here specifically).
|
||||
resource "hpe1810_locator" "draupnir01" {
|
||||
enabled = false
|
||||
}
|
||||
|
||||
data "hpe1810_system_description" "this" {}
|
||||
data "hpe1810_network_setup" "this" {}
|
||||
data "hpe1810_port_summary" "this" {}
|
||||
data "hpe1810_lldp_statistics" "this" {}
|
||||
data "hpe1810_buffered_log" "this" {}
|
||||
data "hpe1810_mac_table" "this" {}
|
||||
data "hpe1810_trunk_status" "this" {}
|
||||
data "hpe1810_loop_protection_status" "this" {}
|
||||
data "hpe1810_dual_image_status" "this" {}
|
||||
data "hpe1810_clock" "this" {}
|
||||
data "hpe1810_sntp" "this" {}
|
||||
data "hpe1810_log_configuration" "this" {}
|
||||
data "hpe1810_backup_manager" "this" {}
|
||||
# Second write resource: Green Features (EEE power-saving). Singleton;
|
||||
# Delete resets to factory defaults (see resource_green_features.go).
|
||||
# Values below match what's currently live on the switch, so the first
|
||||
# `tofu plan` shows no drift.
|
||||
resource "hpe1810_green_features" "draupnir01" {
|
||||
green_mode = true
|
||||
mode_led_time = 10
|
||||
phy_auto_power_down = true
|
||||
}
|
||||
|
||||
# Third write resource: per-port config, driven by for_each over var.ports
|
||||
# (see variables.tf). The admin_port (default 24, see provider.tf) can
|
||||
# never be written by draupnir01 resource regardless of what's in var.ports --
|
||||
# see resource_port.go's guardAdminPort. Delete disables the port and
|
||||
# resets Link Speed to Auto (see resource_port.go for why that's safe here).
|
||||
resource "hpe1810_port" "draupnir01" {
|
||||
for_each = var.ports
|
||||
|
||||
interface = each.key
|
||||
admin_mode = each.value.admin_mode
|
||||
link_speed = each.value.link_speed
|
||||
}
|
||||
|
||||
# Fourth write resource: System Name/Location/Contact (SysDescription.html).
|
||||
# Singleton; only these three fields are actually writable on that page --
|
||||
# see resource_system_description.go. Delete resets all three to "".
|
||||
resource "hpe1810_system_description" "draupnir01" {
|
||||
name = "draupnir01"
|
||||
location = "Lab"
|
||||
contact = ""
|
||||
}
|
||||
|
||||
data "hpe1810_system_description" "draupnir01" {}
|
||||
data "hpe1810_network_setup" "draupnir01" {}
|
||||
data "hpe1810_port_summary" "draupnir01" {}
|
||||
data "hpe1810_lldp_statistics" "draupnir01" {}
|
||||
data "hpe1810_buffered_log" "draupnir01" {}
|
||||
data "hpe1810_mac_table" "draupnir01" {}
|
||||
data "hpe1810_trunk_status" "draupnir01" {}
|
||||
data "hpe1810_loop_protection_status" "draupnir01" {}
|
||||
data "hpe1810_dual_image_status" "draupnir01" {}
|
||||
data "hpe1810_clock" "draupnir01" {}
|
||||
data "hpe1810_sntp" "draupnir01" {}
|
||||
data "hpe1810_log_configuration" "draupnir01" {}
|
||||
data "hpe1810_backup_manager" "draupnir01" {}
|
||||
+17
-5
@@ -1,21 +1,33 @@
|
||||
output "system_description" {
|
||||
description = "Everything read back from the switch's System Description page."
|
||||
value = data.hpe1810_system_description.this
|
||||
value = data.hpe1810_system_description.draupnir01
|
||||
}
|
||||
|
||||
output "system_name" {
|
||||
value = data.hpe1810_system_description.this.name
|
||||
value = data.hpe1810_system_description.draupnir01.name
|
||||
}
|
||||
|
||||
output "port_summary" {
|
||||
value = data.hpe1810_port_summary.this.ports
|
||||
value = data.hpe1810_port_summary.draupnir01.ports
|
||||
}
|
||||
|
||||
output "port_24" {
|
||||
description = "The uplink port -- verifying it's readable without touching it."
|
||||
value = [for p in data.hpe1810_port_summary.this.ports : p if p.Interface == "24"]
|
||||
value = [for p in data.hpe1810_port_summary.draupnir01.ports : p if p.Interface == "24"]
|
||||
}
|
||||
|
||||
output "mac_table" {
|
||||
value = data.hpe1810_mac_table.this
|
||||
value = data.hpe1810_mac_table.draupnir01
|
||||
}
|
||||
|
||||
output "managed_port_status" {
|
||||
description = "physical_type/link_status per port managed via hpe1810_port."
|
||||
value = {
|
||||
for k, p in hpe1810_port.draupnir01 : k => {
|
||||
admin_mode = p.admin_mode
|
||||
link_speed = p.link_speed
|
||||
physical_type = p.physical_type
|
||||
link_status = p.link_status
|
||||
}
|
||||
}
|
||||
}
|
||||
+21
-6
@@ -1,10 +1,11 @@
|
||||
# All three fields are optional. If omitted, each falls back to an env var,
|
||||
# then to a default -- same pattern as config.py in the Python reference
|
||||
# project (SWITCH_HOST / SWITCH_HTTPS / SWITCH_PASSWORD):
|
||||
# All fields are optional. If omitted, each falls back to an env var, then
|
||||
# to a default -- same pattern as config.py in the Python reference project
|
||||
# (SWITCH_HOST / SWITCH_HTTPS / SWITCH_PASSWORD):
|
||||
#
|
||||
# host <- HPE1810_HOST <- "192.168.2.10"
|
||||
# https <- HPE1810_HTTPS <- false
|
||||
# password <- HPE1810_PASSWORD <- ""
|
||||
# host <- HPE1810_HOST <- "192.168.2.10"
|
||||
# https <- HPE1810_HTTPS <- false
|
||||
# password <- HPE1810_PASSWORD <- ""
|
||||
# save_running_config <- HPE1810_SAVE_RUNNING_CONFIG <- false
|
||||
#
|
||||
# So for the switch as currently configured (no password, plain HTTP, at its
|
||||
# default IP), an empty provider block is enough:
|
||||
@@ -17,4 +18,18 @@ provider "hpe1810" {
|
||||
host = "192.168.2.10"
|
||||
https = false
|
||||
password = "" # switch currently has no password set
|
||||
|
||||
# If true, "Save Configuration" runs once at the end of this `tofu`
|
||||
# invocation, but only if it actually wrote something -- a plan-only run,
|
||||
# or an apply where nothing changed, never triggers a save. Left false by
|
||||
# default: the config is already source-of-truth as IaC, and saving on
|
||||
# every write wears the switch's flash for no real benefit. Flip to true
|
||||
# once you actually want changes to survive a reboot/power cycle.
|
||||
save_running_config = false
|
||||
|
||||
# hpe1810_port refuses to write to this interface under any circumstances
|
||||
# -- protects the switch's uplink/management port. Matches the default,
|
||||
# stated explicitly here for clarity. NEVER put this port number in
|
||||
# var.ports (see variables.tf).
|
||||
admin_port = 24
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
# Matches what's currently live on the switch, so `tofu plan` shows no
|
||||
# drift -- port 5 has a manually-fixed 100 Mbps Full Duplex speed
|
||||
# (AutoNeg Status=Disable in port_summary), ports 1-4 are Auto.
|
||||
ports = {
|
||||
"1" = { admin_mode = true, link_speed = "Auto" }
|
||||
"2" = { admin_mode = true, link_speed = "Auto" }
|
||||
"3" = { admin_mode = true, link_speed = "Auto" }
|
||||
"4" = { admin_mode = true, link_speed = "Auto" }
|
||||
"5" = { admin_mode = true, link_speed = "100 Mbps Full Duplex" }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
# Port number (as a string, e.g. "5") -> desired config. NEVER include the
|
||||
# admin_port here (default 24, see provider.tf) -- hpe1810_port refuses to
|
||||
# write to it anyway (see resource_port.go's guardAdminPort), but it's
|
||||
# clearer to just never ask for it.
|
||||
variable "ports" {
|
||||
description = "Port number -> desired Admin Mode / Link Speed."
|
||||
type = map(object({
|
||||
admin_mode = bool
|
||||
link_speed = string
|
||||
}))
|
||||
# No default -- set actual values in terraform.tfvars (or -var-file/-var).
|
||||
}
|
||||
Reference in new issue
Block a user