forked from gavinbunney/terraform-provider-kubectl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Creating the v2 version of the provider
- Loading branch information
1 parent
f237cea
commit b5a233e
Showing
1 changed file
with
14 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,25 @@ | ||
package main | ||
|
||
import ( | ||
kubernetes "github.com/gavinbunney/terraform-provider-kubectl/kubernetes" | ||
goplugin "github.com/hashicorp/go-plugin" | ||
"github.com/hashicorp/terraform-plugin-go/tfprotov5" | ||
tf5server "github.com/hashicorp/terraform-plugin-go/tfprotov5/server" | ||
"flag" | ||
"github.com/alekc/terraform-provider-kubectl/kubernetes" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/plugin" | ||
"google.golang.org/grpc" | ||
) | ||
|
||
func main() { | ||
opts := &plugin.ServeOpts{} | ||
grpcProviderFunc := func() tfprotov5.ProviderServer { | ||
return schema.NewGRPCProviderServer(kubernetes.Provider()) | ||
} | ||
var debug bool | ||
|
||
// taken from github.com/hashicorp/terraform-plugin-sdk/[email protected]/plugin/serve.go | ||
// configured to allow larger message sizes than 4mb | ||
goplugin.Serve(&goplugin.ServeConfig{ | ||
HandshakeConfig: plugin.Handshake, | ||
VersionedPlugins: map[int]goplugin.PluginSet{ | ||
5: { | ||
plugin.ProviderPluginName: &tf5server.GRPCProviderPlugin{ | ||
GRPCProvider: func() tfprotov5.ProviderServer { | ||
return grpcProviderFunc() | ||
}, | ||
}, | ||
}, | ||
}, | ||
GRPCServer: func(opts []grpc.ServerOption) *grpc.Server { | ||
return grpc.NewServer(append(opts, | ||
grpc.MaxSendMsgSize(64<<20 /* 64MB */), | ||
grpc.MaxRecvMsgSize(64<<20 /* 64MB */))...) | ||
flag.BoolVar(&debug, "debug", false, "set to true to run the provider with support for debuggers like delve") | ||
flag.Parse() | ||
|
||
opts := &plugin.ServeOpts{ | ||
Debug: debug, | ||
ProviderAddr: "registry.terraform.io/alekc/kubectl", | ||
ProviderFunc: func() *schema.Provider { | ||
return kubernetes.Provider() | ||
}, | ||
Logger: opts.Logger, | ||
Test: opts.TestConfig, | ||
}) | ||
} | ||
|
||
plugin.Serve(opts) | ||
} |