---
page_title: 'Schema: Migrating from SDKv2 to the Framework'
description: >-
   Migrate a schema from SDKv2 to the plugin Framework.
---

# Schema

Providers, resources, and data sources all use schema to define their attributes and behavior. Schemas specify the
constraints of Terraform configuration blocks and how the provider, resource, or data source behaves. Refer to
[Schemas](/terraform/plugin/framework/handling-data/schemas) in the Framework documentation for details.

This page explains the differences between the schema used by SDKv2 and the Framework. We also recommend reviewing these additional schema guides throughout the migration:
/attributes-blocks/
- [Attributes](/terraform/plugin/framework/migrating/attributes-blocks/attribute-schema) where the schema defines practitioner or provider data associated with a value and type.
- [Attribute types](/terraform/plugin/framework/migrating/attributes-blocks/types) where the schema defines the expected data structure and syntax.
- [Attribute fields](/terraform/plugin/framework/migrating/attributes-blocks/fields) where the behaviors of an attribute are defined, such as `Required`, `Optional`, `Computed`, and `Sensitive`.
- [Attribute defaults](/terraform/plugin/framework/migrating/attributes-blocks/default-values) where the schema defines a value for an attribute which should be automatically included in a Terraform plan if it is not configured by the practitioner.
- [Attributes without in-place updates](/terraform/plugin/framework/migrating/attributes-blocks/force-new) where the schema defines an attribute that requires resource replacement if the value is updated.
- [Attribute predefined validations](/terraform/plugin/framework/migrating/attributes-blocks/validators-predefined) and [custom validations](/terraform/plugin/framework/migrating/attributes-blocks/validators-custom) where the schema defines the syntax, constraints, or encoding expectations of a value.
- [Blocks](/terraform/plugin/framework/migrating/attributes-blocks/attribute-schema) and [computed blocks](/terraform/plugin/framework/migrating/attributes-blocks/blocks-computed) where the schema defines structural configuration sections of data, typically with nested attributes or further blocks.


## Schema Structs

SDKv2 uses `schema.Schema` structs to define the structure, type, and behavior of values drawn from configuration,
state, or plan data. The same `schema.Schema` struct type is used for providers, resources, and data sources. The
schema struct is returned by the function that creates the provider, resource, or data source in question.

The Framework uses `schema.Schema` structs for providers, resources, and data sources. The schema struct is returned by
a `Schema` method you define for the provider and each resource type and data source type. Refer to
[Framework](#framework) for details.

## SDKv2

The following code shows basic implementations using `schema.Schema` structs to define schemas for providers, resources,
and data sources with SDKv2.

```go
func New() *schema.Provider {
    return &schema.Provider{
        Schema: map[string]*schema.Schema{},
        /* ... */
    }
}
```

```go
func resourceExample() *schema.Resource {
    return &schema.Resource{
        Schema: map[string]*schema.Schema{},
        /* ... */
    }
}
```

```go
func dataSourceExample() *schema.Resource {
    return &schema.Resource{
        Schema: map[string]*schema.Schema{},
        /* ... */
    }
}
```

SDKv2 defines the `schema.Schema` struct as follows.

```go
type Schema struct {
    Type                  ValueType
    ConfigMode            SchemaConfigMode
    Required              bool
    Optional              bool
    Computed              bool
    ForceNew              bool
    DiffSuppressFunc      SchemaDiffSuppressFunc
    DiffSuppressOnRefresh bool
    Default               interface{}
    DefaultFunc           SchemaDefaultFunc
    Description           string
    StateFunc             SchemaStateFunc
    Elem                  interface{}
    MaxItems              int
    MinItems              int
    Set                   SchemaSetFunc
    ConflictsWith         []string
    ExactlyOneOf          []string
    AtLeastOneOf          []string
    RequiredWith          []string
    Deprecated            string
    ValidateFunc          SchemaValidateFunc
    ValidateDiagFunc      SchemaValidateDiagFunc
    Sensitive             bool
}
```

## Framework

In the Framework, you implement `Schema` method for your provider, resources, and data sources. This function is
required by the `provider.Provider`, `resource.Resource`, and `datasource.DataSource` interfaces, respectively.

The following code shows how you define the `Schema` method for your provider, resources, and data sources.

```go
func (p *ExampleCloudProvider) Schema(ctx context.Context, req provider.SchemaRequest, resp *provider.SchemaResponse) {
    resp.Schema = schema.Schema{/* ... */}
}
```

```go
func (r *resourceExample) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
    resp.Schema = schema.Schema{/* ... */}
}
```

```go
func (r *dataSourceExample) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
    resp.Schema = schema.Schema{/* ... */}
}
```

You use the `Attributes` field to define attributes for your provider, resources, and data sources. You use the
`Blocks` field to define named blocks.

## Migration Notes

Remember the following differences between SDKv2 and the Framework when completing the migration.

- SDKv2 uses `schema.Schema` structs to define the provider, resources, and data sources. The Framework uses concept-specific
`schema.Schema` structs instead.
- In SDKv2, schema structs are returned when a provider, resource, or data type is created. In the Framework, the
provider and each resource and data type have a `Schema` method that returns the schema.
- In SDKv2, schema structs have a `Set` field which can be populated with a `SchemaSetFunc` which is used for hashing.
In the Framework, this is not required and does not need to be migrated.
- The `schema.Schema` struct includes fields that you use to define
[attributes](/terraform/plugin/framework/migrating/attributes-blocks/attribute-schema) and
[blocks](/terraform/plugin/framework/migrating/attributes-blocks/blocks) for your provider and each resource
and data source.
- When you populate the `Version` field in `schema.Schema` for a resource in the Framework, copy the `Version`
field in `schema.Schema` from the SDKv2 version of that resource.
