Documentation
¶
Index ¶
- Variables
- func GetLatestVersionMatch(versions goversion.Collection, constraints goversion.Constraints) (*goversion.Version, error)
- type ContextKey
- type RegistryType
- type Request
- type Server
- func (s *Server) Cleanup()
- func (s *Server) Get(request Request) error
- func (s *Server) GetAvailableVersions(req VersionsRequest) (goversion.Collection, error)
- func (s *Server) GetDataSourceSchema(request Request, dataSource string) (*tfjson.Schema, error)
- func (s *Server) GetEphemeralResourceSchema(request Request, ephemeralResource string) (*tfjson.Schema, error)
- func (s *Server) GetFunctionSchema(request Request, function string) (*tfjson.FunctionSignature, error)
- func (s *Server) GetProviderSchema(request Request) (*tfjson.Schema, error)
- func (s *Server) GetResourceSchema(request Request, resource string) (*tfjson.Schema, error)
- func (s *Server) ListDataSources(request Request) ([]string, error)
- func (s *Server) ListEphemeralResources(request Request) ([]string, error)
- func (s *Server) ListFunctions(request Request) ([]string, error)
- func (s *Server) ListResources(request Request) ([]string, error)
- type VersionsRequest
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrPluginNotFound = fmt.Errorf("plugin not found") ErrPluginApi = fmt.Errorf("plugin API error") )
var ( // ErrNotImplemented is returned when a method is not implemented ErrNotImplemented = errors.New("not implemented") )
Functions ¶
func GetLatestVersionMatch ¶ added in v0.5.0
func GetLatestVersionMatch(versions goversion.Collection, constraints goversion.Constraints) (*goversion.Version, error)
GetLatestVersionMatch returns the latest version from the provided collection that matches the given constraints. The versions collection must be sorted in ascending order. If no versions match the constraints, an error is returned. If the constraints are nil or empty, the latest version is returned.
Types ¶
type ContextKey ¶ added in v0.2.0
type ContextKey struct{}
ContextKey is a type used to store the server instance in the context.
type RegistryType ¶ added in v0.7.0
type RegistryType string
RegistryType represents the type of provider registry to use.
const ( // RegistryTypeOpenTofu represents the OpenTofu registry (default). RegistryTypeOpenTofu RegistryType = "opentofu" // RegistryTypeTerraform represents the Terraform registry. RegistryTypeTerraform RegistryType = "terraform" )
func (RegistryType) BaseURL ¶ added in v0.7.0
func (r RegistryType) BaseURL() string
BaseURL returns the base URL for the registry API. It defaults to OpenTofu registry for empty or unknown registry types.
type Request ¶
type Request struct {
Namespace string // Namespace of the provider (e.g., "Azure")
Name string // Name of the provider (e.g., "azapi")
Version string // Version of the provider (e.g., "2.5.0") or constraint (e.g., ">=1.0.0", "~>2.1")
RegistryType RegistryType // Registry to use (defaults to OpenTofu if not specified)
}
Request is a request structure used to specify the details of a plugin so that it can be downloaded. Note that the request fields are case-sensitive.
func (Request) String ¶
String returns a string representation of the Request in the format: "https://{registry}/v1/providers/{namespace}/{name}/{version}/download/{os}/{arch}" where {registry} is either registry.opentofu.org (default) or registry.terraform.io. This format is used to construct the URL for downloading the plugin.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is a struct that manages the plugin download and caching process.
func NewServer ¶
NewServer creates a new Server instance with an optional logger. If no logger is provided, it defaults to a logger that discards all logs.
Example ¶
ExampleNewServer demonstrates how to create a new server instance, download a provider, and retrieve its schema. It uses the Azure azapi provider as an example.
package main
import (
"fmt"
"slices"
"github.com/matt-FFFFFF/tfpluginschema"
)
func main() {
s := tfpluginschema.NewServer(nil)
defer s.Cleanup()
request := tfpluginschema.Request{
Namespace: "Azure",
Name: "azapi",
Version: "2.5.0",
}
provSchema, err := s.GetProviderSchema(request)
if err != nil {
panic(err)
}
attrs := make([]string, 0, len(provSchema.Block.Attributes))
for name := range provSchema.Block.Attributes {
attrs = append(attrs, name)
}
slices.Sort(attrs)
for _, name := range attrs {
fmt.Printf("Attribute: %s\n", name)
}
}
Output: Attribute: auxiliary_tenant_ids Attribute: client_certificate Attribute: client_certificate_password Attribute: client_certificate_path Attribute: client_id Attribute: client_id_file_path Attribute: client_secret Attribute: client_secret_file_path Attribute: custom_correlation_request_id Attribute: default_location Attribute: default_name Attribute: default_tags Attribute: disable_correlation_request_id Attribute: disable_default_output Attribute: disable_terraform_partner_id Attribute: enable_preflight Attribute: endpoint Attribute: environment Attribute: ignore_no_op_changes Attribute: maximum_busy_retry_attempts Attribute: oidc_azure_service_connection_id Attribute: oidc_request_token Attribute: oidc_request_url Attribute: oidc_token Attribute: oidc_token_file_path Attribute: partner_id Attribute: skip_provider_registration Attribute: subscription_id Attribute: tenant_id Attribute: use_aks_workload_identity Attribute: use_cli Attribute: use_msi Attribute: use_oidc
Example (TerraformRegistry) ¶
ExampleNewServer_terraformRegistry demonstrates how to use the Terraform registry instead of the default OpenTofu registry. It uses the HashiCorp random provider as an example.
package main
import (
"fmt"
"slices"
"github.com/matt-FFFFFF/tfpluginschema"
)
func main() {
s := tfpluginschema.NewServer(nil)
defer s.Cleanup()
request := tfpluginschema.Request{
Namespace: "Azure",
Name: "azapi",
Version: "2.5.0",
RegistryType: tfpluginschema.RegistryTypeTerraform,
}
provSchema, err := s.GetProviderSchema(request)
if err != nil {
panic(err)
}
attrs := make([]string, 0, len(provSchema.Block.Attributes))
for name := range provSchema.Block.Attributes {
attrs = append(attrs, name)
}
slices.Sort(attrs)
for _, name := range attrs {
fmt.Printf("Attribute: %s\n", name)
}
}
Output: Attribute: auxiliary_tenant_ids Attribute: client_certificate Attribute: client_certificate_password Attribute: client_certificate_path Attribute: client_id Attribute: client_id_file_path Attribute: client_secret Attribute: client_secret_file_path Attribute: custom_correlation_request_id Attribute: default_location Attribute: default_name Attribute: default_tags Attribute: disable_correlation_request_id Attribute: disable_default_output Attribute: disable_terraform_partner_id Attribute: enable_preflight Attribute: endpoint Attribute: environment Attribute: ignore_no_op_changes Attribute: maximum_busy_retry_attempts Attribute: oidc_azure_service_connection_id Attribute: oidc_request_token Attribute: oidc_request_url Attribute: oidc_token Attribute: oidc_token_file_path Attribute: partner_id Attribute: skip_provider_registration Attribute: subscription_id Attribute: tenant_id Attribute: use_aks_workload_identity Attribute: use_cli Attribute: use_msi Attribute: use_oidc
func (*Server) Cleanup ¶
func (s *Server) Cleanup()
Cleanup removes the temporary directory used for plugin downloads.
func (*Server) Get ¶
Get retrieves the plugin for the specified request, downloading it if necessary. The GetXxx methods (GetResourceSchema, GetDataSourceSchema, etc.) will call this method anyway, so it is not necessary to call Get directly unless you want to ensure the plugin is downloaded first. It is stored in a temporary directory and cached for future use. Make sure to call Cleanup() to remove the temporary files.
func (*Server) GetAvailableVersions ¶ added in v0.5.0
func (s *Server) GetAvailableVersions(req VersionsRequest) (goversion.Collection, error)
GetAvailableVersions fetches the available versions for the given provider from the plugin registry. It caches the results to avoid redundant network calls. It returns a sorted collection of versions.
func (*Server) GetDataSourceSchema ¶
GetDataSourceSchema retrieves the schema for a specific data source from the provider.
func (*Server) GetEphemeralResourceSchema ¶ added in v0.2.0
func (s *Server) GetEphemeralResourceSchema(request Request, ephemeralResource string) (*tfjson.Schema, error)
GetEphemeralResourceSchema retrieves the schema for a specific ephemeral resource from the provider.
func (*Server) GetFunctionSchema ¶
func (s *Server) GetFunctionSchema(request Request, function string) (*tfjson.FunctionSignature, error)
GetFunctionSchema retrieves the schema for a specific function from the provider.
func (*Server) GetProviderSchema ¶ added in v0.3.0
GetProviderSchema retrieves the schema for the provider configuration.
func (*Server) GetResourceSchema ¶
GetResourceSchema retrieves the schema for a specific resource from the provider.
func (*Server) ListDataSources ¶ added in v0.4.0
ListDataSources retrieves the list of data source names from the provider.
func (*Server) ListEphemeralResources ¶ added in v0.4.0
ListEphemeralResources retrieves the list of ephemeral resource names from the provider.
func (*Server) ListFunctions ¶ added in v0.4.0
ListFunctions retrieves the list of function names from the provider.
type VersionsRequest ¶ added in v0.5.0
type VersionsRequest struct {
Namespace string // Namespace of the provider (e.g., "hashicorp")
Name string // Name of the provider (e.g., "aws")
RegistryType RegistryType // Registry to use (defaults to OpenTofu if not specified)
}
func (VersionsRequest) String ¶ added in v0.5.0
func (v VersionsRequest) String() string