Skip to content

Commit 2e8cf26

Browse files
committed
chore: add mux to support terraform framework
1 parent a45426c commit 2e8cf26

File tree

15 files changed

+197
-17
lines changed

15 files changed

+197
-17
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ require (
2121
github.com/hashicorp/go-cty v1.5.0
2222
github.com/hashicorp/go-multierror v1.1.1
2323
github.com/hashicorp/go-retryablehttp v0.7.8
24+
github.com/hashicorp/terraform-plugin-framework v1.15.1
2425
github.com/hashicorp/terraform-plugin-go v0.29.0
2526
github.com/hashicorp/terraform-plugin-log v0.9.0
2627
github.com/hashicorp/terraform-plugin-mux v0.21.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,8 @@ github.com/hashicorp/terraform-json v0.27.2 h1:BwGuzM6iUPqf9JYM/Z4AF1OJ5VVJEEzoK
324324
github.com/hashicorp/terraform-json v0.27.2/go.mod h1:GzPLJ1PLdUG5xL6xn1OXWIjteQRT2CNT9o/6A9mi9hE=
325325
github.com/hashicorp/terraform-plugin-docs v0.23.0 h1:sipnfD4/9EJBg9zekym+s1H6qmLAKJHhGWBwvN9v/hE=
326326
github.com/hashicorp/terraform-plugin-docs v0.23.0/go.mod h1:J4b5AtMRgJlDrwCQz+G4hKABgHY5m56PnsRmdAzBwW8=
327+
github.com/hashicorp/terraform-plugin-framework v1.15.1 h1:2mKDkwb8rlx/tvJTlIcpw0ykcmvdWv+4gY3SIgk8Pq8=
328+
github.com/hashicorp/terraform-plugin-framework v1.15.1/go.mod h1:hxrNI/GY32KPISpWqlCoTLM9JZsGH3CyYlir09bD/fI=
327329
github.com/hashicorp/terraform-plugin-go v0.29.0 h1:1nXKl/nSpaYIUBU1IG/EsDOX0vv+9JxAltQyDMpq5mU=
328330
github.com/hashicorp/terraform-plugin-go v0.29.0/go.mod h1:vYZbIyvxyy0FWSmDHChCqKvI40cFTDGSb3D8D70i9GM=
329331
github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0=

internal/acctest/acctest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func NewTestTools(t *testing.T) *TestTools {
6666
Meta: m,
6767
ProviderFactories: map[string]func() (*schema.Provider, error){
6868
"scaleway": func() (*schema.Provider, error) {
69-
return provider.Provider(&provider.Config{Meta: m})(), nil
69+
return provider.SDKProvider(&provider.Config{Meta: m})(), nil
7070
},
7171
},
7272
Cleanup: cleanup,

internal/acctest/fixtures.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func FakeSideProjectProviders(ctx context.Context, tt *TestTools, project *accou
3232

3333
providers := map[string]func() (*schema.Provider, error){
3434
"side": func() (*schema.Provider, error) {
35-
return provider.Provider(&provider.Config{Meta: metaSide})(), nil
35+
return provider.SDKProvider(&provider.Config{Meta: metaSide})(), nil
3636
},
3737
}
3838

internal/locality/regional/schemas.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ func Schema() *schema.Schema {
3131
Description: "The region you want to attach the resource to",
3232
Optional: true,
3333
ForceNew: true,
34-
Computed: true,
3534
ValidateDiagFunc: locality.ValidateStringInSliceWithWarning(allRegions(), "region"),
3635
}
3736
}

internal/locality/zonal/schemas.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ func Schema() *schema.Schema {
3131
Description: "The zone you want to attach the resource to",
3232
Optional: true,
3333
ForceNew: true,
34-
Computed: true,
3534
ValidateDiagFunc: locality.ValidateStringInSliceWithWarning(AllZones(), "zone"),
3635
}
3736
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package provider
2+
3+
import (
4+
"context"
5+
6+
"github.com/hashicorp/terraform-plugin-framework/datasource"
7+
"github.com/hashicorp/terraform-plugin-framework/ephemeral"
8+
"github.com/hashicorp/terraform-plugin-framework/provider"
9+
"github.com/hashicorp/terraform-plugin-framework/provider/schema"
10+
"github.com/hashicorp/terraform-plugin-framework/resource"
11+
)
12+
13+
var _ provider.Provider = &ScalewayProvider{}
14+
15+
type ScalewayProvider struct{}
16+
17+
func NewFrameworkProvider() func() provider.Provider {
18+
return func() provider.Provider {
19+
return &ScalewayProvider{}
20+
}
21+
}
22+
23+
func (p *ScalewayProvider) Metadata(ctx context.Context, req provider.MetadataRequest, resp *provider.MetadataResponse) {
24+
resp.TypeName = "scaleway"
25+
}
26+
27+
func (p *ScalewayProvider) Schema(ctx context.Context, req provider.SchemaRequest, resp *provider.SchemaResponse) {
28+
resp.Schema = schema.Schema{
29+
Attributes: map[string]schema.Attribute{
30+
"access_key": schema.StringAttribute{
31+
Optional: true,
32+
Description: "The Scaleway access key.",
33+
},
34+
"secret_key": schema.StringAttribute{
35+
Optional: true,
36+
Description: "The Scaleway secret Key.",
37+
},
38+
"profile": schema.StringAttribute{
39+
Optional: true,
40+
Description: "The Scaleway profile to use.",
41+
},
42+
"project_id": schema.StringAttribute{
43+
Optional: true,
44+
Description: "The Scaleway project ID.",
45+
},
46+
"organization_id": schema.StringAttribute{
47+
Optional: true,
48+
Description: "The Scaleway organization ID.",
49+
},
50+
"api_url": schema.StringAttribute{
51+
Optional: true,
52+
Description: "The Scaleway API URL to use.",
53+
},
54+
"region": schema.StringAttribute{
55+
Optional: true,
56+
Description: "The region you want to attach the resource to",
57+
},
58+
"zone": schema.StringAttribute{
59+
Description: "The zone you want to attach the resource to",
60+
Optional: true,
61+
},
62+
},
63+
}
64+
}
65+
66+
func (p *ScalewayProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) {
67+
}
68+
69+
func (p *ScalewayProvider) Resources(ctx context.Context) []func() resource.Resource {
70+
return []func() resource.Resource{}
71+
}
72+
73+
func (p *ScalewayProvider) EphemeralResources(_ context.Context) []func() ephemeral.EphemeralResource {
74+
return []func() ephemeral.EphemeralResource{}
75+
}
76+
77+
func (p *ScalewayProvider) DataSources(_ context.Context) []func() datasource.DataSource {
78+
return []func() datasource.DataSource{}
79+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package provider_test
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
"github.com/hashicorp/terraform-plugin-framework/providerserver"
8+
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
9+
"github.com/hashicorp/terraform-plugin-mux/tf5muxserver"
10+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
11+
"github.com/scaleway/terraform-provider-scaleway/v2/internal/acctest"
12+
"github.com/scaleway/terraform-provider-scaleway/v2/internal/provider"
13+
instancechecks "github.com/scaleway/terraform-provider-scaleway/v2/internal/services/instance/testfuncs"
14+
)
15+
16+
func TestMuxServer(t *testing.T) {
17+
tt := acctest.NewTestTools(t)
18+
defer tt.Cleanup()
19+
20+
resource.Test(t, resource.TestCase{
21+
ProtoV5ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error){
22+
"scaleway": func() (tfprotov5.ProviderServer, error) {
23+
ctx := context.Background()
24+
providers := []func() tfprotov5.ProviderServer{
25+
providerserver.NewProtocol5(provider.NewFrameworkProvider()()), // terraform-plugin-framework provider
26+
provider.SDKProvider(provider.DefaultConfig())().GRPCProvider, // terraform-plugin-sdk provider
27+
}
28+
29+
muxServer, err := tf5muxserver.NewMuxServer(ctx, providers...)
30+
31+
if err != nil {
32+
return nil, err
33+
}
34+
35+
return muxServer.ProviderServer(), nil
36+
},
37+
},
38+
Steps: []resource.TestStep{
39+
{
40+
Config: `
41+
resource scaleway_instance_ip main {}`,
42+
Check: resource.ComposeTestCheckFunc(
43+
instancechecks.CheckIPExists(tt, "scaleway_instance_ip.main"),
44+
),
45+
},
46+
},
47+
})
48+
}

internal/provider/provider.go renamed to internal/provider/provider_sdkv2.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ func addBetaResources(provider *schema.Provider) {
8282
}
8383
}
8484

85-
// Provider returns a terraform.ResourceProvider.
86-
func Provider(config *Config) plugin.ProviderFunc {
85+
// SDKProvider returns a terraform.ResourceProvider.
86+
func SDKProvider(config *Config) plugin.ProviderFunc {
8787
return func() *schema.Provider {
8888
p := &schema.Provider{
8989
Schema: map[string]*schema.Schema{

internal/provider/provider_test.go renamed to internal/provider/provider_sdkv2_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ func TestAccProvider_InstanceIPZones(t *testing.T) {
4040

4141
return map[string]func() (*schema.Provider, error){
4242
"prod": func() (*schema.Provider, error) {
43-
return provider.Provider(&provider.Config{Meta: metaProd})(), nil
43+
return provider.SDKProvider(&provider.Config{Meta: metaProd})(), nil
4444
},
4545
"dev": func() (*schema.Provider, error) {
46-
return provider.Provider(&provider.Config{Meta: metaDev})(), nil
46+
return provider.SDKProvider(&provider.Config{Meta: metaDev})(), nil
4747
},
4848
}
4949
}(),
@@ -96,10 +96,10 @@ func TestAccProvider_SSHKeys(t *testing.T) {
9696

9797
return map[string]func() (*schema.Provider, error){
9898
"prod": func() (*schema.Provider, error) {
99-
return provider.Provider(&provider.Config{Meta: metaProd})(), nil
99+
return provider.SDKProvider(&provider.Config{Meta: metaProd})(), nil
100100
},
101101
"dev": func() (*schema.Provider, error) {
102-
return provider.Provider(&provider.Config{Meta: metaDev})(), nil
102+
return provider.SDKProvider(&provider.Config{Meta: metaDev})(), nil
103103
},
104104
}
105105
}(),

0 commit comments

Comments
 (0)