diff --git a/scaleway/baremetal.go b/scaleway/baremetal.go index 8d11b64..0c11619 100644 --- a/scaleway/baremetal.go +++ b/scaleway/baremetal.go @@ -69,7 +69,7 @@ func (b *baremetal) InstanceID(ctx context.Context, nodeName types.NodeName) (st if err != nil { return "", err } - return BuildProviderID(InstanceTypeBaremtal, string(baremetalServer.Zone), baremetalServer.ID), nil + return BuildInstanceID(InstanceTypeBaremtal, string(baremetalServer.Zone), baremetalServer.ID), nil } // InstanceType returns the type of the specified instance. diff --git a/scaleway/baremetal_test.go b/scaleway/baremetal_test.go index 29a469c..17d9141 100644 --- a/scaleway/baremetal_test.go +++ b/scaleway/baremetal_test.go @@ -207,7 +207,7 @@ func TestBaremetal_InstanceID(t *testing.T) { t.Run("Found", func(t *testing.T) { result, err := baremetal.InstanceID(context.TODO(), "bm-keen-feistel") AssertNoError(t, err) - Equals(t, "scaleway://baremetal/fr-par-2/53a6ca14-0d8d-4f2e-9887-2f1bcfba58ed", result) + Equals(t, "baremetal/fr-par-2/53a6ca14-0d8d-4f2e-9887-2f1bcfba58ed", result) }) t.Run("NotFound", func(t *testing.T) { diff --git a/scaleway/instances.go b/scaleway/instances.go index a9c2d34..fd3da06 100644 --- a/scaleway/instances.go +++ b/scaleway/instances.go @@ -69,7 +69,7 @@ func (i *instances) InstanceID(ctx context.Context, name types.NodeName) (string if err != nil { return "", err } - return BuildProviderID(InstanceTypeInstance, string(instanceServer.Zone), instanceServer.ID), nil + return BuildInstanceID(InstanceTypeInstance, string(instanceServer.Zone), instanceServer.ID), nil } // InstanceType returns the type of the specified instance (ex. DEV1-M, GP1-XS,...). diff --git a/scaleway/instances_test.go b/scaleway/instances_test.go index 1dfb87b..bf51975 100644 --- a/scaleway/instances_test.go +++ b/scaleway/instances_test.go @@ -219,7 +219,7 @@ func TestInstances_InstanceID(t *testing.T) { t.Run("Found", func(t *testing.T) { result, err := instance.InstanceID(context.TODO(), "scw-nervous-mccarthy") AssertNoError(t, err) - Equals(t, "scaleway://instance/fr-par-1/232bf860-9ffe-4b08-97da-158c0316ed15", result) + Equals(t, "instance/fr-par-1/232bf860-9ffe-4b08-97da-158c0316ed15", result) }) t.Run("NotFound", func(t *testing.T) { diff --git a/scaleway/servers.go b/scaleway/servers.go index b881dfa..abc16e7 100644 --- a/scaleway/servers.go +++ b/scaleway/servers.go @@ -68,9 +68,14 @@ func ServerInfoFromProviderID(providerID string) (string, string, string, error) return result[regexpProduct], result[regexpLocalization], result[regexpUUID], nil } +// BuildInstanceID build the instanceID from given informations +func BuildInstanceID(product, localization, id string) string { + return fmt.Sprintf("%s/%s/%s", product, localization, id) +} + // BuildProviderID build the providerID from given informations func BuildProviderID(product, localization, id string) string { - return fmt.Sprintf("%s://%s/%s/%s", providerName, product, localization, id) + return fmt.Sprintf("%s://%s", providerName, BuildInstanceID(product, localization, id)) } // getImplementationByProviderID returns the corresponding cloudprovider.Instances implementation