From 03203dc4f34a2620700d7d537006d6a47c347548 Mon Sep 17 00:00:00 2001 From: Pavel Boldyrev <627562+bpg@users.noreply.github.com> Date: Wed, 30 Jul 2025 08:05:51 -0400 Subject: [PATCH] refactor: simplify genericAttributesWith function signature and logic - Updated the genericAttributesWith function to accept a single map of attributes instead of a variadic argument. - Improved the logic to initialize and merge attributes, ensuring that extra attributes can override the generic ones. - Adjusted the SimpleResource schema to call genericAttributesWith with nil for clarity. Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> --- .../cluster/sdn/zone/resource_generic.go | 22 +++++++++---------- .../cluster/sdn/zone/resource_simple.go | 2 +- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/fwprovider/cluster/sdn/zone/resource_generic.go b/fwprovider/cluster/sdn/zone/resource_generic.go index 3c4e9005..94efe910 100644 --- a/fwprovider/cluster/sdn/zone/resource_generic.go +++ b/fwprovider/cluster/sdn/zone/resource_generic.go @@ -68,16 +68,9 @@ func (m *genericModel) getID() string { return m.ID.ValueString() } -func genericAttributesWith(extraAttributes ...map[string]schema.Attribute) map[string]schema.Attribute { - if len(extraAttributes) > 1 { - panic("genericAttributesWith expects at most one extraAttributes map") - } - - if len(extraAttributes) == 0 { - extraAttributes = append(extraAttributes, make(map[string]schema.Attribute)) - } - - maps.Copy(extraAttributes[0], map[string]schema.Attribute{ +func genericAttributesWith(extraAttributes map[string]schema.Attribute) map[string]schema.Attribute { + // Start with generic attributes as the base + result := map[string]schema.Attribute{ "dns": schema.StringAttribute{ Optional: true, Description: "DNS API server address.", @@ -116,9 +109,14 @@ func genericAttributesWith(extraAttributes ...map[string]schema.Attribute) map[s Optional: true, Description: "Reverse DNS API server address.", }, - }) + } - return extraAttributes[0] + // Add extra attributes, allowing them to override generic ones if needed + if extraAttributes != nil { + maps.Copy(result, extraAttributes) + } + + return result } type zoneModel interface { diff --git a/fwprovider/cluster/sdn/zone/resource_simple.go b/fwprovider/cluster/sdn/zone/resource_simple.go index d8de0ae5..71866b7d 100644 --- a/fwprovider/cluster/sdn/zone/resource_simple.go +++ b/fwprovider/cluster/sdn/zone/resource_simple.go @@ -44,7 +44,7 @@ func (r *SimpleResource) Schema(_ context.Context, _ resource.SchemaRequest, res MarkdownDescription: "Simple Zone in Proxmox SDN. It will create an isolated VNet bridge. " + "This bridge is not linked to a physical interface, and VM traffic is only local on each the node. " + "It can be used in NAT or routed setups.", - Attributes: genericAttributesWith(), + Attributes: genericAttributesWith(nil), } }