Skip to content

Commit

Permalink
Merge pull request #716 from Juniper/feat/715-sort-resource-group-names
Browse files Browse the repository at this point in the history
Sort resource group names in `utils.AllResourceGroupNameStrings()`
  • Loading branch information
chrismarget-j authored Jul 12, 2024
2 parents df0cef4 + 01433d1 commit 7240766
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
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
}

0 comments on commit 7240766

Please sign in to comment.