|
@@ -5,89 +5,126 @@ package provider
|
|
|
|
|
|
import (
|
|
import (
|
|
"context"
|
|
"context"
|
|
- "net/http"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
|
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
|
- "github.com/hashicorp/terraform-plugin-framework/function"
|
|
|
|
"github.com/hashicorp/terraform-plugin-framework/provider"
|
|
"github.com/hashicorp/terraform-plugin-framework/provider"
|
|
"github.com/hashicorp/terraform-plugin-framework/provider/schema"
|
|
"github.com/hashicorp/terraform-plugin-framework/provider/schema"
|
|
"github.com/hashicorp/terraform-plugin-framework/resource"
|
|
"github.com/hashicorp/terraform-plugin-framework/resource"
|
|
- "github.com/hashicorp/terraform-plugin-framework/types"
|
|
|
|
)
|
|
)
|
|
|
|
|
|
-// Ensure ScaffoldingProvider satisfies various provider interfaces.
|
|
|
|
-var _ provider.Provider = &ScaffoldingProvider{}
|
|
|
|
-var _ provider.ProviderWithFunctions = &ScaffoldingProvider{}
|
|
|
|
|
|
+// Ensure hashicupsProvider satisfies various provider interfaces.
|
|
|
|
+var _ provider.Provider = &hashicupsProvider{}
|
|
|
|
|
|
-// ScaffoldingProvider defines the provider implementation.
|
|
|
|
-type ScaffoldingProvider struct {
|
|
|
|
|
|
+// New is a helper function to simplify provider server and testing implementation.
|
|
|
|
+func New(version string) func() provider.Provider {
|
|
|
|
+ return func() provider.Provider {
|
|
|
|
+ return &hashicupsProvider{
|
|
|
|
+ version: version,
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// hashicupsProvider defines the provider implementation.
|
|
|
|
+type hashicupsProvider struct {
|
|
// version is set to the provider version on release, "dev" when the
|
|
// version is set to the provider version on release, "dev" when the
|
|
// provider is built and ran locally, and "test" when running acceptance
|
|
// provider is built and ran locally, and "test" when running acceptance
|
|
// testing.
|
|
// testing.
|
|
version string
|
|
version string
|
|
}
|
|
}
|
|
|
|
|
|
-// ScaffoldingProviderModel describes the provider data model.
|
|
|
|
-type ScaffoldingProviderModel struct {
|
|
|
|
- Endpoint types.String `tfsdk:"endpoint"`
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func (p *ScaffoldingProvider) Metadata(ctx context.Context, req provider.MetadataRequest, resp *provider.MetadataResponse) {
|
|
|
|
- resp.TypeName = "scaffolding"
|
|
|
|
|
|
+func (p *hashicupsProvider) Metadata(_ context.Context, _ provider.MetadataRequest, resp *provider.MetadataResponse) {
|
|
|
|
+ resp.TypeName = "hashicups"
|
|
resp.Version = p.version
|
|
resp.Version = p.version
|
|
}
|
|
}
|
|
|
|
|
|
-func (p *ScaffoldingProvider) Schema(ctx context.Context, req provider.SchemaRequest, resp *provider.SchemaResponse) {
|
|
|
|
- resp.Schema = schema.Schema{
|
|
|
|
- Attributes: map[string]schema.Attribute{
|
|
|
|
- "endpoint": schema.StringAttribute{
|
|
|
|
- MarkdownDescription: "Example provider attribute",
|
|
|
|
- Optional: true,
|
|
|
|
- },
|
|
|
|
- },
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func (p *ScaffoldingProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) {
|
|
|
|
- var data ScaffoldingProviderModel
|
|
|
|
-
|
|
|
|
- resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
|
|
|
|
-
|
|
|
|
- if resp.Diagnostics.HasError() {
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // Configuration values are now available.
|
|
|
|
- // if data.Endpoint.IsNull() { /* ... */ }
|
|
|
|
-
|
|
|
|
- // Example client configuration for data sources and resources
|
|
|
|
- client := http.DefaultClient
|
|
|
|
- resp.DataSourceData = client
|
|
|
|
- resp.ResourceData = client
|
|
|
|
|
|
+func (p *hashicupsProvider) Schema(_ context.Context, _ provider.SchemaRequest, resp *provider.SchemaResponse) {
|
|
|
|
+ resp.Schema = schema.Schema{}
|
|
}
|
|
}
|
|
|
|
|
|
-func (p *ScaffoldingProvider) Resources(ctx context.Context) []func() resource.Resource {
|
|
|
|
- return []func() resource.Resource{
|
|
|
|
- NewExampleResource,
|
|
|
|
- }
|
|
|
|
|
|
+func (p *hashicupsProvider) Configure(_ context.Context, _ provider.ConfigureRequest, _ *provider.ConfigureResponse) {
|
|
}
|
|
}
|
|
|
|
|
|
-func (p *ScaffoldingProvider) DataSources(ctx context.Context) []func() datasource.DataSource {
|
|
|
|
- return []func() datasource.DataSource{
|
|
|
|
- NewExampleDataSource,
|
|
|
|
- }
|
|
|
|
|
|
+func (p *hashicupsProvider) DataSources(_ context.Context) []func() datasource.DataSource {
|
|
|
|
+ return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (p *ScaffoldingProvider) Functions(ctx context.Context) []func() function.Function {
|
|
|
|
- return []func() function.Function{
|
|
|
|
- NewExampleFunction,
|
|
|
|
- }
|
|
|
|
|
|
+func (p *hashicupsProvider) Resources(_ context.Context) []func() resource.Resource {
|
|
|
|
+ return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func New(version string) func() provider.Provider {
|
|
|
|
- return func() provider.Provider {
|
|
|
|
- return &ScaffoldingProvider{
|
|
|
|
- version: version,
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
|
|
+//// Ensure hashicupsProvider satisfies various provider interfaces.
|
|
|
|
+//var _ provider.Provider = &hashicupsProvider{}
|
|
|
|
+//var _ provider.ProviderWithFunctions = &hashicupsProvider{}
|
|
|
|
+//
|
|
|
|
+//// hashicupsProvider defines the provider implementation.
|
|
|
|
+//type hashicupsProvider struct {
|
|
|
|
+// // version is set to the provider version on release, "dev" when the
|
|
|
|
+// // provider is built and ran locally, and "test" when running acceptance
|
|
|
|
+// // testing.
|
|
|
|
+// version string
|
|
|
|
+//}
|
|
|
|
+//
|
|
|
|
+//// ScaffoldingProviderModel describes the provider data model.
|
|
|
|
+//type ScaffoldingProviderModel struct {
|
|
|
|
+// Endpoint types.String `tfsdk:"endpoint"`
|
|
|
|
+//}
|
|
|
|
+//
|
|
|
|
+//func (p *hashicupsProvider) Metadata(ctx context.Context, req provider.MetadataRequest, resp *provider.MetadataResponse) {
|
|
|
|
+// resp.TypeName = "scaffolding"
|
|
|
|
+// resp.Version = p.version
|
|
|
|
+//}
|
|
|
|
+//
|
|
|
|
+//func (p *hashicupsProvider) Schema(ctx context.Context, req provider.SchemaRequest, resp *provider.SchemaResponse) {
|
|
|
|
+// resp.Schema = schema.Schema{
|
|
|
|
+// Attributes: map[string]schema.Attribute{
|
|
|
|
+// "endpoint": schema.StringAttribute{
|
|
|
|
+// MarkdownDescription: "Example provider attribute",
|
|
|
|
+// Optional: true,
|
|
|
|
+// },
|
|
|
|
+// },
|
|
|
|
+// }
|
|
|
|
+//}
|
|
|
|
+//
|
|
|
|
+//func (p *hashicupsProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) {
|
|
|
|
+// var data ScaffoldingProviderModel
|
|
|
|
+//
|
|
|
|
+// resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
|
|
|
|
+//
|
|
|
|
+// if resp.Diagnostics.HasError() {
|
|
|
|
+// return
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// // Configuration values are now available.
|
|
|
|
+// // if data.Endpoint.IsNull() { /* ... */ }
|
|
|
|
+//
|
|
|
|
+// // Example client configuration for data sources and resources
|
|
|
|
+// client := http.DefaultClient
|
|
|
|
+// resp.DataSourceData = client
|
|
|
|
+// resp.ResourceData = client
|
|
|
|
+//}
|
|
|
|
+//
|
|
|
|
+//func (p *hashicupsProvider) Resources(ctx context.Context) []func() resource.Resource {
|
|
|
|
+// return []func() resource.Resource{
|
|
|
|
+// NewExampleResource,
|
|
|
|
+// }
|
|
|
|
+//}
|
|
|
|
+//
|
|
|
|
+//func (p *hashicupsProvider) DataSources(ctx context.Context) []func() datasource.DataSource {
|
|
|
|
+// return []func() datasource.DataSource{
|
|
|
|
+// NewExampleDataSource,
|
|
|
|
+// }
|
|
|
|
+//}
|
|
|
|
+//
|
|
|
|
+//func (p *hashicupsProvider) Functions(ctx context.Context) []func() function.Function {
|
|
|
|
+// return []func() function.Function{
|
|
|
|
+// NewExampleFunction,
|
|
|
|
+// }
|
|
|
|
+//}
|
|
|
|
+//
|
|
|
|
+//func New(version string) func() provider.Provider {
|
|
|
|
+// return func() provider.Provider {
|
|
|
|
+// return &hashicupsProvider{
|
|
|
|
+// version: version,
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+//}
|