Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort resource group names in utils.AllResourceGroupNameStrings() #716

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions apstra/blueprint/pool_allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package blueprint
import (
"context"
"fmt"
"strings"

"github.com/Juniper/apstra-go-sdk/apstra"
apstravalidator "github.com/Juniper/terraform-provider-apstra/apstra/apstra_validator"
"github.com/Juniper/terraform-provider-apstra/apstra/utils"
Expand All @@ -15,22 +17,17 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"sort"
"strings"
)

type PoolAllocation struct {
BlueprintId types.String `tfsdk:"blueprint_id"`
Role types.String `tfsdk:"role"`
PoolIds types.Set `tfsdk:"pool_ids"`
RoutingZoneId types.String `tfsdk:"routing_zone_id"`
//PoolAllocationId types.String `tfsdk:"pool_allocation_id"` // placeholder for freeform
// PoolAllocationId types.String `tfsdk:"pool_allocation_id"` // placeholder for freeform
}

func (o PoolAllocation) ResourceAttributes() map[string]resourceSchema.Attribute {
sortedRoles := utils.AllResourceGroupNameStrings()
sort.Strings(sortedRoles)

return map[string]resourceSchema.Attribute{
"blueprint_id": resourceSchema.StringAttribute{
MarkdownDescription: "Apstra ID of the Blueprint to which the Resource Pool should be allocated.",
Expand All @@ -49,7 +46,7 @@ func (o PoolAllocation) ResourceAttributes() map[string]resourceSchema.Attribute
},
"role": resourceSchema.StringAttribute{
MarkdownDescription: "Fabric Role (Apstra Resource Group Name) must be one of:\n\n - " +
strings.Join(sortedRoles, "\n - ") + "\n",
strings.Join(utils.AllResourceGroupNameStrings(), "\n - ") + "\n",
Required: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.RequiresReplace()},
Validators: []validator.String{
Expand All @@ -72,7 +69,7 @@ func (o PoolAllocation) ResourceAttributes() map[string]resourceSchema.Attribute
path.Expressions{
path.MatchRelative(),
// other blueprint objects to which pools can be assigned must be listed here
//path.MatchRoot("pool_allocation_id"), //placeholder for freeform
// path.MatchRoot("pool_allocation_id"), //placeholder for freeform
}...,
),
},
Expand Down
8 changes: 7 additions & 1 deletion apstra/utils/resource_group.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package utils

import "github.com/Juniper/apstra-go-sdk/apstra"
import (
"sort"

"github.com/Juniper/apstra-go-sdk/apstra"
)

func AllResourceGroupNameStrings() []string {
argn := apstra.AllResourceGroupNames()
Expand All @@ -11,5 +15,7 @@ func AllResourceGroupNameStrings() []string {
}
result = append(result, StringersToFriendlyString(rgn))
}

sort.Strings(result)
return result
}
Loading