Im new to golang and Im playing with writing a custom terraform module (terraform is written in go)
I went through the beginner golang tuts so I have some understanding of pointers, structs, methods, closures, etc, but Im still a little befuddled by this. I’m getting a little ahead of myself but I’m appreciate any assistance in helping understand what Im looking at here:
package main
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/plugin"
"terraform-provider-hashicups/hashicups"
)
func main() {
/////// This is what I want to understand- this whole call chain
plugin.Serve(&plugin.ServeOpts{
ProviderFunc: func() *schema.Provider {
return hashicups.Provider()
},
})
}
Is this what is happening?..
- Im calling the
Serve()
method of theplugin
module - Im passing the same instance of the plugin object to its own Serve() method? And modifying the plugin objects state right? Sort of like a singleton?
- Im overriding the default ServeOpts struct of the plugin object with this one im passing in?
- The ServerOpts struct has a ProviderFunc field which holds a function. Im overriding that function with this one im passing in. The function Im passing is an anonymous function, the definition of which specifies it returns a pointer to schema.Provider and Im returning my own hashicups.Provider() there
The ProviderFunc is a function type in the module as well- I dont think I totally understand the utility of having it be a type
Still have a lot to learn but Id like to get some grasp of whats actually happening here