|
1 | 1 | package main |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "github.com/hashicorp/terraform-plugin-sdk/v2/plugin" |
| 4 | + "context" |
| 5 | + "flag" |
| 6 | + "log" |
| 7 | + |
| 8 | + "github.com/hashicorp/terraform-plugin-framework/providerserver" |
| 9 | + |
| 10 | + "github.com/hashicorp/terraform-plugin-go/tfprotov6" |
| 11 | + "github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server" |
| 12 | + "github.com/hashicorp/terraform-plugin-mux/tf5to6server" |
| 13 | + "github.com/hashicorp/terraform-plugin-mux/tf6muxserver" |
5 | 14 |
|
6 | 15 | "github.com/coder/terraform-provider-coder/v2/provider" |
| 16 | + "github.com/coder/terraform-provider-coder/v2/tpfprovider" |
7 | 17 | ) |
8 | 18 |
|
9 | 19 | // Run the docs generation tool, check its repository for more information on how it works and how docs |
10 | 20 | // can be customized. |
11 | 21 | //go:generate go run github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs |
12 | 22 |
|
13 | 23 | func main() { |
| 24 | + ctx := context.Background() |
| 25 | + var debug bool |
| 26 | + flag.BoolVar(&debug, "debug", false, "enable debug logging") |
| 27 | + flag.Parse() |
| 28 | + |
14 | 29 | servePprof() |
15 | | - plugin.Serve(&plugin.ServeOpts{ |
16 | | - ProviderFunc: provider.New, |
17 | | - }) |
| 30 | + |
| 31 | + upgradedSDKServer, err := tf5to6server.UpgradeServer( |
| 32 | + ctx, |
| 33 | + provider.New().GRPCProvider, |
| 34 | + ) |
| 35 | + if err != nil { |
| 36 | + log.Fatal(err) |
| 37 | + } |
| 38 | + |
| 39 | + providers := []func() tfprotov6.ProviderServer{ |
| 40 | + providerserver.NewProtocol6(tpfprovider.NewFrameworkProvider()), |
| 41 | + func() tfprotov6.ProviderServer { |
| 42 | + return upgradedSDKServer |
| 43 | + }, |
| 44 | + } |
| 45 | + |
| 46 | + muxServer, err := tf6muxserver.NewMuxServer(ctx, providers...) |
| 47 | + if err != nil { |
| 48 | + log.Fatal(err) |
| 49 | + } |
| 50 | + |
| 51 | + var serveOpts []tf6server.ServeOpt |
| 52 | + if debug { |
| 53 | + serveOpts = append(serveOpts, tf6server.WithManagedDebug()) |
| 54 | + } |
| 55 | + |
| 56 | + err = tf6server.Serve( |
| 57 | + "registry.terraform.io/coder/coder", |
| 58 | + muxServer.ProviderServer, |
| 59 | + serveOpts..., |
| 60 | + ) |
| 61 | + |
| 62 | + if err != nil { |
| 63 | + log.Fatal(err) |
| 64 | + } |
18 | 65 | } |
0 commit comments