mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-08-28 14:25:37 +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:
parent
520e7b4594
commit
03203dc4f3
@ -68,16 +68,9 @@ func (m *genericModel) getID() string {
|
|||||||
return m.ID.ValueString()
|
return m.ID.ValueString()
|
||||||
}
|
}
|
||||||
|
|
||||||
func genericAttributesWith(extraAttributes ...map[string]schema.Attribute) map[string]schema.Attribute {
|
func genericAttributesWith(extraAttributes map[string]schema.Attribute) map[string]schema.Attribute {
|
||||||
if len(extraAttributes) > 1 {
|
// Start with generic attributes as the base
|
||||||
panic("genericAttributesWith expects at most one extraAttributes map")
|
result := map[string]schema.Attribute{
|
||||||
}
|
|
||||||
|
|
||||||
if len(extraAttributes) == 0 {
|
|
||||||
extraAttributes = append(extraAttributes, make(map[string]schema.Attribute))
|
|
||||||
}
|
|
||||||
|
|
||||||
maps.Copy(extraAttributes[0], map[string]schema.Attribute{
|
|
||||||
"dns": schema.StringAttribute{
|
"dns": schema.StringAttribute{
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Description: "DNS API server address.",
|
Description: "DNS API server address.",
|
||||||
@ -116,9 +109,14 @@ func genericAttributesWith(extraAttributes ...map[string]schema.Attribute) map[s
|
|||||||
Optional: true,
|
Optional: true,
|
||||||
Description: "Reverse DNS API server address.",
|
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 {
|
type zoneModel interface {
|
||||||
|
@ -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. " +
|
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. " +
|
"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.",
|
"It can be used in NAT or routed setups.",
|
||||||
Attributes: genericAttributesWith(),
|
Attributes: genericAttributesWith(nil),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user