Skip to content

Commit

Permalink
update provider
Browse files Browse the repository at this point in the history
  • Loading branch information
futuretea authored and guangbochen committed Jul 22, 2021
1 parent 7bdfb5a commit e350da6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 28 deletions.
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T
github.com/hashicorp/hcl/v2 v2.3.0/go.mod h1:d+FwDBbOLvpAM3Z6J7gPj/VoAGkNe/gm352ZhjJ/Zv8=
github.com/hashicorp/hcl/v2 v2.8.2 h1:wmFle3D1vu0okesm8BTLVDyJ6/OL9DCLUwn0b2OptiY=
github.com/hashicorp/hcl/v2 v2.8.2/go.mod h1:bQTN5mpo+jewjJgh8jr0JUguIi7qPHUF6yIfAEN3jqY=
github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y=
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
Expand Down
44 changes: 21 additions & 23 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,31 @@ import (
"github.com/harvester/terraform-provider-harvester/pkg/constants"
)

func New(version string) func() *schema.Provider {
return func() *schema.Provider {
p := &schema.Provider{
Schema: map[string]*schema.Schema{
constants.FiledProviderKubeConfig: {
Type: schema.TypeString,
Optional: true,
Default: "",
Description: "harvester kubeconfig",
},
func Provider() *schema.Provider {
p := &schema.Provider{
Schema: map[string]*schema.Schema{
constants.FiledProviderKubeConfig: {
Type: schema.TypeString,
Optional: true,
Default: "",
Description: "harvester kubeconfig",
},
DataSourcesMap: map[string]*schema.Resource{},
ResourcesMap: map[string]*schema.Resource{
constants.ResourceTypeImage: image.ResourceImage(),
constants.ResourceTypeKeyPair: keypair.ResourceKeypair(),
constants.ResourceTypeNetwork: network.ResourceNetwork(),
constants.ResourceTypeVirtualMachine: virtualmachine.ResourceVirtualMachine(),
constants.ResourceTypeVolume: volume.ResourceVolume(),
constants.ResourceTypeClusterNetwork: clusternetwork.ResourceClusterNetwork(),
},
}
p.ConfigureContextFunc = configure(version, p)
return p
},
DataSourcesMap: map[string]*schema.Resource{},
ResourcesMap: map[string]*schema.Resource{
constants.ResourceTypeImage: image.ResourceImage(),
constants.ResourceTypeKeyPair: keypair.ResourceKeypair(),
constants.ResourceTypeNetwork: network.ResourceNetwork(),
constants.ResourceTypeVirtualMachine: virtualmachine.ResourceVirtualMachine(),
constants.ResourceTypeVolume: volume.ResourceVolume(),
constants.ResourceTypeClusterNetwork: clusternetwork.ResourceClusterNetwork(),
},
}
p.ConfigureContextFunc = configure(p)
return p
}

func configure(version string, p *schema.Provider) schema.ConfigureContextFunc {
func configure(p *schema.Provider) schema.ConfigureContextFunc {
return func(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
kubeConfig := d.Get(constants.FiledProviderKubeConfig).(string)
c, err := client.NewClient(kubeConfig)
Expand Down
6 changes: 1 addition & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,12 @@ import (
//go:generate terraform fmt -recursive ./examples/
//go:generate go run github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs

var (
version = "dev"
)

func main() {
var debugMode bool

flag.BoolVar(&debugMode, "debug", false, "set to true to run the provider with support for debuggers like delve")
flag.Parse()
opts := &plugin.ServeOpts{ProviderFunc: provider.New(version)}
opts := &plugin.ServeOpts{ProviderFunc: provider.Provider}

if debugMode {
err := plugin.Debug(context.Background(), "registry.terraform.io/harvester/harvester", opts)
Expand Down

0 comments on commit e350da6

Please sign in to comment.