Skip to content

Commit 24acb78

Browse files
committed
use semver pkg for major minor
1 parent 00e0d85 commit 24acb78

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ require (
3333
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.35.0.20251017125838-3eb0f2adaa94
3434
github.com/stretchr/testify v1.11.1
3535
golang.org/x/crypto v0.43.0
36+
golang.org/x/mod v0.29.0
3637
golang.org/x/sync v0.17.0
3738
gopkg.in/dnaeon/go-vcr.v3 v3.2.0
3839
gopkg.in/dnaeon/go-vcr.v4 v4.0.5
@@ -162,7 +163,6 @@ require (
162163
go.opentelemetry.io/otel/metric v1.38.0 // indirect
163164
go.opentelemetry.io/otel/trace v1.38.0 // indirect
164165
golang.org/x/exp v0.0.0-20251009144603-d2f985daa21b // indirect
165-
golang.org/x/mod v0.29.0 // indirect
166166
golang.org/x/net v0.46.0 // indirect
167167
golang.org/x/sys v0.37.0 // indirect
168168
golang.org/x/term v0.36.0 // indirect

internal/services/k8s/k8s_version_data_source.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import (
44
"context"
55
"errors"
66
"fmt"
7-
"strings"
87

98
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
109
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1110
"github.com/scaleway/scaleway-sdk-go/api/k8s/v1"
1211
"github.com/scaleway/scaleway-sdk-go/scw"
1312
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/regional"
13+
"golang.org/x/mod/semver"
1414
)
1515

1616
func DataSourceVersion() *schema.Resource {
@@ -94,11 +94,9 @@ func DataSourceK8SVersionRead(ctx context.Context, d *schema.ResourceData, m any
9494
version = res
9595
}
9696

97-
withoutPatch := strings.Join(strings.Split(version.Name, ".")[:2], ".")
98-
9997
d.SetId(fmt.Sprintf("%s/%s", region, version.Name))
10098
_ = d.Set("name", version.Name)
101-
_ = d.Set("major_minor_only", withoutPatch)
99+
_ = d.Set("major_minor_only", semver.MajorMinor(version.Name))
102100
_ = d.Set("available_cnis", version.AvailableCnis)
103101
_ = d.Set("available_container_runtimes", version.AvailableContainerRuntimes)
104102
_ = d.Set("available_feature_gates", version.AvailableFeatureGates)

internal/services/k8s/k8s_version_data_source_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ package k8s_test
22

33
import (
44
"fmt"
5-
"strings"
65
"testing"
76

87
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
98
"github.com/hashicorp/terraform-plugin-testing/terraform"
109
"github.com/scaleway/scaleway-sdk-go/api/k8s/v1"
1110
"github.com/scaleway/terraform-provider-scaleway/v2/internal/acctest"
1211
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/regional"
12+
"golang.org/x/mod/semver"
1313
)
1414

1515
func TestAccDataSourceVersion_Basic(t *testing.T) {
@@ -85,7 +85,7 @@ func TestAccDataSourceVersion_WithAutoUpgrade(t *testing.T) {
8585
defer tt.Cleanup()
8686

8787
latestK8SVersion := testAccK8SClusterGetLatestK8SVersion(tt)
88-
latestK8SVersionWithoutPatch := strings.Join(strings.Split(latestK8SVersion, ".")[:2], ".")
88+
latestK8SVersionWithoutPatch := semver.MajorMinor(latestK8SVersion)
8989

9090
resource.ParallelTest(t, resource.TestCase{
9191
ProtoV6ProviderFactories: tt.ProviderFactories,

0 commit comments

Comments
 (0)