Migrate to new schema packages (#103)

This commit is contained in:
Brian Flad 2022-12-10 17:15:03 -08:00 committed by GitHub
parent 8b3d10ea3b
commit aed8000e78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 30 deletions

View File

@ -6,8 +6,7 @@ import (
"net/http" "net/http"
"github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog" "github.com/hashicorp/terraform-plugin-log/tflog"
) )
@ -34,24 +33,22 @@ func (d *ExampleDataSource) Metadata(ctx context.Context, req datasource.Metadat
resp.TypeName = req.ProviderTypeName + "_example" resp.TypeName = req.ProviderTypeName + "_example"
} }
func (d *ExampleDataSource) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Diagnostics) { func (d *ExampleDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
return tfsdk.Schema{ resp.Schema = schema.Schema{
// This description is used by the documentation generator and the language server. // This description is used by the documentation generator and the language server.
MarkdownDescription: "Example data source", MarkdownDescription: "Example data source",
Attributes: map[string]tfsdk.Attribute{ Attributes: map[string]schema.Attribute{
"configurable_attribute": { "configurable_attribute": schema.StringAttribute{
MarkdownDescription: "Example configurable attribute", MarkdownDescription: "Example configurable attribute",
Optional: true, Optional: true,
Type: types.StringType,
}, },
"id": { "id": schema.StringAttribute{
MarkdownDescription: "Example identifier", MarkdownDescription: "Example identifier",
Type: types.StringType,
Computed: true, Computed: true,
}, },
}, },
}, nil }
} }
func (d *ExampleDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { func (d *ExampleDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {

View File

@ -5,10 +5,11 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog" "github.com/hashicorp/terraform-plugin-log/tflog"
) )
@ -36,27 +37,25 @@ func (r *ExampleResource) Metadata(ctx context.Context, req resource.MetadataReq
resp.TypeName = req.ProviderTypeName + "_example" resp.TypeName = req.ProviderTypeName + "_example"
} }
func (r *ExampleResource) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Diagnostics) { func (r *ExampleResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
return tfsdk.Schema{ resp.Schema = schema.Schema{
// This description is used by the documentation generator and the language server. // This description is used by the documentation generator and the language server.
MarkdownDescription: "Example resource", MarkdownDescription: "Example resource",
Attributes: map[string]tfsdk.Attribute{ Attributes: map[string]schema.Attribute{
"configurable_attribute": { "configurable_attribute": schema.StringAttribute{
MarkdownDescription: "Example configurable attribute", MarkdownDescription: "Example configurable attribute",
Optional: true, Optional: true,
Type: types.StringType,
}, },
"id": { "id": schema.StringAttribute{
Computed: true, Computed: true,
MarkdownDescription: "Example identifier", MarkdownDescription: "Example identifier",
PlanModifiers: tfsdk.AttributePlanModifiers{ PlanModifiers: []planmodifier.String{
resource.UseStateForUnknown(), stringplanmodifier.UseStateForUnknown(),
}, },
Type: types.StringType,
}, },
}, },
}, nil }
} }
func (r *ExampleResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { func (r *ExampleResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {

View File

@ -5,10 +5,9 @@ import (
"net/http" "net/http"
"github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/diag"
"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/resource" "github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-framework/types"
) )
@ -34,16 +33,15 @@ func (p *ScaffoldingProvider) Metadata(ctx context.Context, req provider.Metadat
resp.Version = p.version resp.Version = p.version
} }
func (p *ScaffoldingProvider) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Diagnostics) { func (p *ScaffoldingProvider) Schema(ctx context.Context, req provider.SchemaRequest, resp *provider.SchemaResponse) {
return tfsdk.Schema{ resp.Schema = schema.Schema{
Attributes: map[string]tfsdk.Attribute{ Attributes: map[string]schema.Attribute{
"endpoint": { "endpoint": schema.StringAttribute{
MarkdownDescription: "Example provider attribute", MarkdownDescription: "Example provider attribute",
Optional: true, Optional: true,
Type: types.StringType,
}, },
}, },
}, nil }
} }
func (p *ScaffoldingProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) { func (p *ScaffoldingProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) {