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

(CLOUDDEV-440): Change to new go client data_source_edgecenter_region #43

Closed
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
6 changes: 3 additions & 3 deletions edgecenter/data_source_edgecenter_region.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ func dataSourceRegion() *schema.Resource {
}
}

func dataSourceRegionRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
func dataSourceRegionRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Println("[DEBUG] Start Region reading")

name := d.Get("name").(string)
config := m.(*Config)
provider := config.Provider
regionID, err := GetRegion(provider, 0, name)
clientV2 := config.CloudClient
regionID, err := GetRegion(ctx, clientV2, 0, name)
if err != nil {
return diag.FromErr(err)
}
Expand Down
20 changes: 5 additions & 15 deletions edgecenter/utils_region.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package edgecenter

import (
"context"
"fmt"
"log"

edgecloud "github.com/Edge-Center/edgecentercloud-go"
"github.com/Edge-Center/edgecentercloud-go/edgecenter"
"github.com/Edge-Center/edgecentercloud-go/edgecenter/region/v1/regions"
edgecloudV2 "github.com/Edge-Center/edgecentercloud-go/v2"
)

// findRegionByName searches for a region with the specified name in the provided region slice.
// Returns the region ID if found, otherwise returns an error.
func findRegionByName(arr []regions.Region, name string) (int, error) {
func findRegionByName(arr []edgecloudV2.Region, name string) (int, error) {
for _, el := range arr {
if el.DisplayName == name {
return el.ID, nil
Expand All @@ -24,21 +23,12 @@ func findRegionByName(arr []regions.Region, name string) (int, error) {
// If the regionID is provided, it will be returned directly.
// If regionName is provided instead, the function will search for the region by name and return its ID.
// Returns an error if the region is not found or there is an issue with the client.
func GetRegion(provider *edgecloud.ProviderClient, regionID int, regionName string) (int, error) {
func GetRegion(ctx context.Context, client *edgecloudV2.Client, regionID int, regionName string) (int, error) {
if regionID != 0 {
return regionID, nil
}
client, err := edgecenter.ClientServiceFromProvider(provider, edgecloud.EndpointOpts{
Name: RegionPoint,
Region: 0,
Project: 0,
Version: VersionPointV1,
})
if err != nil {
return 0, err
}

rs, err := regions.ListAll(client)
rs, _, err := client.Regions.List(ctx, nil)
if err != nil {
return 0, err
}
Expand Down