diff --git a/equinix/fabric_service_profile_read_schema.go b/equinix/fabric_service_profile_read_schema.go index 02c7a5cd6..887b4dd50 100755 --- a/equinix/fabric_service_profile_read_schema.go +++ b/equinix/fabric_service_profile_read_schema.go @@ -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": { diff --git a/equinix/fabric_service_profile_search_schema.go b/equinix/fabric_service_profile_search_schema.go index c0c7a46c9..7814f8404 100755 --- a/equinix/fabric_service_profile_search_schema.go +++ b/equinix/fabric_service_profile_search_schema.go @@ -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, diff --git a/equinix/resource_fabric_service_profile.go b/equinix/resource_fabric_service_profile.go index fdaf46cbb..a7b91524a 100755 --- a/equinix/resource_fabric_service_profile.go +++ b/equinix/resource_fabric_service_profile.go @@ -2,7 +2,9 @@ package equinix import ( "context" + "errors" "fmt" + "github.com/antihax/optional" "log" "strconv" "strings" @@ -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) { + 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{}