0
0
mirror of https://github.com/bpg/terraform-provider-proxmox.git synced 2025-08-28 06:15:44 +00:00

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>
This commit is contained in:
Pavel Boldyrev 2025-07-30 08:05:51 -04:00
parent 520e7b4594
commit 03203dc4f3
No known key found for this signature in database
GPG Key ID: 637146A2A6804C59
2 changed files with 11 additions and 13 deletions

View File

@ -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 {

View File

@ -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),
}
}