123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- package provider
- import (
- "context"
- "fmt"
- "github.com/hashicorp/terraform-plugin-framework/diag"
- "github.com/hashicorp/terraform-plugin-framework/tfsdk"
- "github.com/hashicorp/terraform-plugin-framework/types"
- )
- type provider struct {
-
-
-
-
-
-
-
-
-
- configured bool
-
-
-
- version string
- }
- type providerData struct {
- Example types.String `tfsdk:"example"`
- }
- func (p *provider) Configure(ctx context.Context, req tfsdk.ConfigureProviderRequest, resp *tfsdk.ConfigureProviderResponse) {
- var data providerData
- diags := req.Config.Get(ctx, &data)
- resp.Diagnostics.Append(diags...)
- if resp.Diagnostics.HasError() {
- return
- }
-
-
-
-
- p.configured = true
- }
- func (p *provider) GetResources(ctx context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) {
- return map[string]tfsdk.ResourceType{
- "scaffolding_example": exampleResourceType{},
- }, nil
- }
- func (p *provider) GetDataSources(ctx context.Context) (map[string]tfsdk.DataSourceType, diag.Diagnostics) {
- return map[string]tfsdk.DataSourceType{
- "scaffolding_example": exampleDataSourceType{},
- }, nil
- }
- func (p *provider) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Diagnostics) {
- return tfsdk.Schema{
- Attributes: map[string]tfsdk.Attribute{
- "example": {
- MarkdownDescription: "Example provider attribute",
- Optional: true,
- Type: types.StringType,
- },
- },
- }, nil
- }
- func New(version string) func() tfsdk.Provider {
- return func() tfsdk.Provider {
- return &provider{
- version: version,
- }
- }
- }
- func convertProviderType(in tfsdk.Provider) (provider, diag.Diagnostics) {
- var diags diag.Diagnostics
- p, ok := in.(*provider)
- if !ok {
- diags.AddError(
- "Unexpected Provider Instance Type",
- fmt.Sprintf("While creating the data source or resource, an unexpected provider type (%T) was received. This is always a bug in the provider code and should be reported to the provider developers.", p),
- )
- return provider{}, diags
- }
- if p == nil {
- diags.AddError(
- "Unexpected Provider Instance Type",
- "While creating the data source or resource, an unexpected empty provider instance was received. This is always a bug in the provider code and should be reported to the provider developers.",
- )
- return provider{}, diags
- }
- return *p, diags
- }
|