Skip to content

Commit ff3d0b3

Browse files
committed
chore: migrate to terraform protocol v6
1 parent 8a8c029 commit ff3d0b3

File tree

4 files changed

+35
-22
lines changed

4 files changed

+35
-22
lines changed

internal/acctest/acctest.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"testing"
99
"time"
1010

11-
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
11+
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
1212
"github.com/hashicorp/terraform-plugin-mux/tf5muxserver"
1313
"github.com/scaleway/terraform-provider-scaleway/v2/internal/env"
1414
"github.com/scaleway/terraform-provider-scaleway/v2/internal/meta"
@@ -22,7 +22,7 @@ func PreCheck(_ *testing.T) {}
2222
type TestTools struct {
2323
T *testing.T
2424
Meta *meta.Meta
25-
ProviderFactories map[string]func() (tfprotov5.ProviderServer, error)
25+
ProviderFactories map[string]func() (tfprotov6.ProviderServer, error)
2626
Cleanup func()
2727
}
2828

@@ -66,8 +66,8 @@ func NewTestTools(t *testing.T) *TestTools {
6666
return &TestTools{
6767
T: t,
6868
Meta: m,
69-
ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error){
70-
"scaleway": func() (tfprotov5.ProviderServer, error) {
69+
ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
70+
"scaleway": func() (tfprotov6.ProviderServer, error) {
7171
ctx := context.Background()
7272
providers := provider.NewProviderList(&provider.Config{Meta: m})
7373

internal/acctest/fixtures.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package acctest
33
import (
44
"context"
55

6-
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
6+
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
77
"github.com/hashicorp/terraform-plugin-mux/tf5muxserver"
88
sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
99
"github.com/scaleway/scaleway-sdk-go/api/account/v3"
@@ -18,7 +18,7 @@ import (
1818
// given project and API key as default profile configuration.
1919
//
2020
// This is useful to test resources that need to create resources in another project.
21-
func FakeSideProjectProviders(ctx context.Context, tt *TestTools, project *account.Project, iamAPIKey *iam.APIKey) map[string]func() (tfprotov5.ProviderServer, error) {
21+
func FakeSideProjectProviders(ctx context.Context, tt *TestTools, project *account.Project, iamAPIKey *iam.APIKey) map[string]func() (tfprotov6.ProviderServer, error) {
2222
t := tt.T
2323

2424
metaSide, err := meta.NewMeta(ctx, &meta.Config{
@@ -31,8 +31,8 @@ func FakeSideProjectProviders(ctx context.Context, tt *TestTools, project *accou
3131
})
3232
require.NoError(t, err)
3333

34-
providers := map[string]func() (tfprotov5.ProviderServer, error){
35-
"side": func() (tfprotov5.ProviderServer, error) {
34+
providers := map[string]func() (tfprotov6.ProviderServer, error){
35+
"side": func() (tfprotov6.ProviderServer, error) {
3636
providers := provider.NewProviderList(&provider.Config{Meta: metaSide})
3737

3838
muxServer, err := tf5muxserver.NewMuxServer(ctx, providers...)

internal/provider/providers.go

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
11
package provider
22

33
import (
4+
"context"
5+
46
"github.com/hashicorp/terraform-plugin-framework/providerserver"
5-
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
7+
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
8+
"github.com/hashicorp/terraform-plugin-mux/tf5to6server"
69
)
710

8-
func NewProviderList(config *Config) []func() tfprotov5.ProviderServer {
9-
return []func() tfprotov5.ProviderServer{
10-
// Provider using terraform-plugin-framework
11-
providerserver.NewProtocol5(&ScalewayProvider{}),
12-
13-
// SDKProvider using terraform-plugin-sdk
11+
func NewProviderList(ctx context.Context, config *Config) ([]func() tfprotov6.ProviderServer, error) {
12+
// SDKProvider using terraform-plugin-sdk
13+
upgradedSdkProvider, err := tf5to6server.UpgradeServer(
14+
ctx,
1415
SDKProvider(config)().GRPCProvider,
16+
)
17+
if err != nil {
18+
return nil, err
1519
}
20+
21+
return []func() tfprotov6.ProviderServer{
22+
// Provider using terraform-plugin-framework
23+
providerserver.NewProtocol6(&ScalewayProvider{}),
24+
25+
func() tfprotov6.ProviderServer {
26+
return upgradedSdkProvider
27+
},
28+
}, nil
1629
}

main.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"flag"
66
"log"
77

8-
"github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server"
9-
"github.com/hashicorp/terraform-plugin-mux/tf5muxserver"
8+
"github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server"
9+
"github.com/hashicorp/terraform-plugin-mux/tf6muxserver"
1010
"github.com/scaleway/terraform-provider-scaleway/v2/internal/provider"
1111
)
1212

@@ -18,19 +18,19 @@ func main() {
1818
flag.BoolVar(&debugMode, "debuggable", false, "set to true to run the provider with support for debuggers like delve")
1919
flag.Parse()
2020

21-
var serveOpts []tf5server.ServeOpt
21+
var serveOpts []tf6server.ServeOpt
2222
if debugMode {
23-
serveOpts = append(serveOpts, tf5server.WithManagedDebug())
23+
serveOpts = append(serveOpts, tf6server.WithManagedDebug())
2424
}
2525

26-
providers := provider.NewProviderList(nil)
26+
providers, err := provider.NewProviderList(ctx, nil)
2727

28-
muxServer, err := tf5muxserver.NewMuxServer(ctx, providers...)
28+
muxServer, err := tf6muxserver.NewMuxServer(ctx, providers...)
2929
if err != nil {
3030
log.Fatal(err)
3131
}
3232

33-
err = tf5server.Serve(
33+
err = tf6server.Serve(
3434
"registry.terraform.io/scaleway/scaleway",
3535
muxServer.ProviderServer,
3636
serveOpts...,

0 commit comments

Comments
 (0)