Skip to content

Commit

Permalink
Add viewPoint parameter to Service Profiles Data Resource
Browse files Browse the repository at this point in the history
  • Loading branch information
thogarty committed Oct 17, 2023
1 parent ceb588a commit ecb79c5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
8 changes: 7 additions & 1 deletion equinix/fabric_service_profile_read_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,12 +446,18 @@ func readFabricServiceProfilesSearchSchema() map[string]*schema.Schema {
Schema: readFabricServiceProfileSchemaUpdated(),
},
},
"view_point": {
Type: schema.TypeString,
Optional: true,
Description: "flips view between buyer and seller representation. Available values : aSide, zSide. Default value : aSide",
},
"filter": {
Type: schema.TypeSet,
Optional: true,
Description: "Service Profile Search Filter",
MaxItems: 1,
Elem: &schema.Resource{
Schema: createServiceProfilesSearchExpressionSch(),
Schema: createServiceProfilesSearchFilterSch(),
},
},
"sort": {
Expand Down
2 changes: 1 addition & 1 deletion equinix/fabric_service_profile_search_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

func createServiceProfilesSearchExpressionSch() map[string]*schema.Schema {
func createServiceProfilesSearchFilterSch() map[string]*schema.Schema {
return map[string]*schema.Schema{
"property": {
Type: schema.TypeString,
Expand Down
18 changes: 17 additions & 1 deletion equinix/resource_fabric_service_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package equinix

import (
"context"
"errors"
"fmt"
"github.com/antihax/optional"
"log"
"strconv"
"strings"
Expand Down Expand Up @@ -279,11 +281,25 @@ func resourceServiceProfilesSearchRequest(ctx context.Context, d *schema.Resourc
serviceProfileFlt = filter
schemaSort := d.Get("sort").([]interface{})
sort := serviceProfilesSearchSortRequestToFabric(schemaSort)
schemaViewPoint := d.Get("view_point").(string)

if schemaViewPoint != "" && (schemaViewPoint != string(v4.A_SIDE_ViewPoint) || schemaViewPoint != string(v4.Z_SIDE_ViewPoint)) {

Check failure on line 286 in equinix/resource_fabric_service_profile.go

View workflow job for this annotation

GitHub Actions / Test

suspect or: schemaViewPoint != string(v4.A_SIDE_ViewPoint) || schemaViewPoint != string(v4.Z_SIDE_ViewPoint)

Check failure on line 286 in equinix/resource_fabric_service_profile.go

View workflow job for this annotation

GitHub Actions / Matrix Test (stable, 1.5)

suspect or: schemaViewPoint != string(v4.A_SIDE_ViewPoint) || schemaViewPoint != string(v4.Z_SIDE_ViewPoint)

Check failure on line 286 in equinix/resource_fabric_service_profile.go

View workflow job for this annotation

GitHub Actions / Matrix Test (stable, 1.5)

suspect or: schemaViewPoint != string(v4.A_SIDE_ViewPoint) || schemaViewPoint != string(v4.Z_SIDE_ViewPoint)
return diag.FromErr(errors.New("view_point can only be set to aSide or zSide. Omitting it will default to aSide"))
}

viewPoint := &v4.ServiceProfilesApiSearchServiceProfilesOpts{
ViewPoint: optional.NewString(schemaViewPoint),
}

if schemaViewPoint == "" {
viewPoint = nil
}

createServiceProfilesSearchRequest := v4.ServiceProfileSearchRequest{
Filter: &serviceProfileFlt,
Sort: sort,
}
serviceProfiles, _, err := client.ServiceProfilesApi.SearchServiceProfiles(ctx, createServiceProfilesSearchRequest, nil)
serviceProfiles, _, err := client.ServiceProfilesApi.SearchServiceProfiles(ctx, createServiceProfilesSearchRequest, viewPoint)
if err != nil {
if !strings.Contains(err.Error(), "500") {
error := v4.ModelError{}
Expand Down

0 comments on commit ecb79c5

Please sign in to comment.