---
page_title: 'Attribute Fields: Migrating from SDKv2 to the Framework'
description: >-
  Migrate attribute required, optional, computed, and sensitive fields from SDKv2 to the plugin Framework
---

# Attribute Fields

A subset of attribute fields, such as required, optional, computed, or sensitive, define attribute behavior as boolean flags. Refer to
[Schemas - Attributes](/terraform/plugin/framework/handling-data/schemas#required) in the Framework documentation for details.

The following table describes the mapping between [SDK Schema Fields](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-sdk/helper/schema#Schema) and the Framework.

| SDK Schema Field      | Framework                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
|-----------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Type                  | [Attribute Types](/terraform/plugin/framework/migrating/attributes-blocks/types)                                                                                                                                                                                                                                                                                                                                                                                       |
| ConfigMode            | Schema must be explictly defined using [Attributes](/terraform/plugin/framework/migrating/attributes-blocks/attribute-schema) and [Blocks](/terraform/plugin/framework/migrating/attributes-blocks/blocks)                                                                                                                                                                                                                                                             |
| Required              | `Required` field on attribute                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| Optional              | `Optional` field on attribute                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| Computed              | `Computed` field on attribute                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| ForceNew              | [RequiresReplace](/terraform/plugin/framework/migrating/attributes-blocks/force-new) on `PlanModifiers` field on attribute or implementation of [ResourceWithModifyPlan](/terraform/plugin/framework/migrating/resources/plan-modification#framework) interface                                                                                                                                                                                                        |
| DiffSuppressFunc      | [Custom Types](/terraform/plugin/framework/handling-data/types/custom), [PlanModifiers](/terraform/plugin/framework/migrating/resources/plan-modification#framework) field on attribute, or implementation of [ResourceWithModifyPlan](/terraform/plugin/framework/migrating/resources/plan-modification#framework) interface                                                                                                                                                                                                                   |
| DiffSuppressOnRefresh | [Custom Types](/terraform/plugin/framework/handling-data/types/custom) semantic equality logic or manual logic in [Read](/terraform/plugin/framework/migrating/resources/crud) method on resource                                                                                                                                                                                                                                                                                                                                                                                        |
| Default               | `Default` field on attribute using one of the predefined [Defaults](/terraform/plugin/framework/resources/default#common-use-case-attribute-defaults) or implementing one of the [`schema` package](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/resource/schema/defaults) interfaces                                                                                                                                                            |
| DefaultFunc           | `Default` field on attribute using one of the predefined [Defaults](/terraform/plugin/framework/resources/default#common-use-case-attribute-defaults) or implementing one of the [`schema` package](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/resource/schema/defaults) interfaces                                                                                                                                                            |
| Description           | `Description` field on attribute                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| InputDefault          | N/A - no longer valid                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| StateFunc             | Requires implementation of bespoke logic before storing state, for instance in resource [Create method](/terraform/plugin/framework/migrating/resources/crud#framework-1)                                                                                                                                                                                                                                                                                              |
| Elem                  | `ElementType` on [ListAttribute](/terraform/plugin/framework/migrating/attributes-blocks/types), [MapAttribute](/terraform/plugin/framework/migrating/attributes-blocks/types) or [SetAttribute](/terraform/plugin/framework/migrating/attributes-blocks/types). Refer to [Blocks](/terraform/plugin/framework/migrating/attributes-blocks/blocks) if `schema.Resource` is present in `Elem`.                                                                          |
| MaxItems              | Use [listValidator.SizeAtMost](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework-validators/listvalidator#SizeAtMost), [mapvalidator.SizeAtMost](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework-validators/mapvalidator#SizeAtMost) or [setvalidator.SizeAtMost](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator#SizeAtMost) on `Validators` field on list, map or set attribute       |
| MinItems              | Use [listValidator.SizeAtLeast](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework-validators/listvalidator#SizeAtLeast), [mapvalidator.SizeAtLeast](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework-validators/mapvalidator#SizeAtLeast) or [setvalidator.SizeAtLeast](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator#SizeAtLeast) on `Validators` field on list, map or set attribute |
| Set                   | N/A - no implementation required                                                                                                                                                                                                                                                                                                                                                                                                                                       |                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| ComputedWhen          | N/A - no longer valid                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ConflictsWith         | [Predefined Validators](/terraform/plugin/framework/migrating/attributes-blocks/validators-predefined)                                                                                                                                                                                                                                                                                                                                                                 |
| ExactlyOneOf          | [Predefined Validators](/terraform/plugin/framework/migrating/attributes-blocks/validators-predefined)                                                                                                                                                                                                                                                                                                                                                                 |
| AtLeastOneOf          | [Predefined Validators](/terraform/plugin/framework/migrating/attributes-blocks/validators-predefined)                                                                                                                                                                                                                                                                                                                                                                 |
| RequiredWith          | [Predefined Validators](/terraform/plugin/framework/migrating/attributes-blocks/validators-predefined)                                                                                                                                                                                                                                                                                                                                                                 |
| Deprecated            | `DeprecationMessage` field on attribute                                                                                                                                                                                                                                                                                                                                                                                                                                |
| ValidateFunc          | [Predefined Validators](/terraform/plugin/framework/migrating/attributes-blocks/validators-predefined), [Custom Validators](/terraform/plugin/framework/migrating/attributes-blocks/validators-custom), or [Custom Types](/terraform/plugin/framework/handling-data/types/custom) validation logic                                                                                                                                                                                                                                                              |
| ValidateDiagFunc      | [Predefined Validators](/terraform/plugin/framework/migrating/attributes-blocks/validators-predefined), [Custom Validators](/terraform/plugin/framework/migrating/attributes-blocks/validators-custom), or [Custom Types](/terraform/plugin/framework/handling-data/types/custom) validation logic                                                                                                                                                                                                                                                              |
| Sensitive             | `Sensitive` field on attribute                                                                                                                                                                                                                                                                                                                                                                                                                                         |


This page explains how to migrate the required, optional, computed, and sensitive attribute fields from SDKv2 to the
Framework.

## SDKv2

In SDKv2, `Required`, `Optional`, `Computed`, and `Sensitive` are boolean fields on the attribute's schema.

```go
func resourceExample() *schema.Resource {
    return &schema.Resource{
         /* ... */
        Schema: map[string]*schema.Schema{
            "attribute_example": {
                Required:    bool
                Optional:    bool
                Computed:    bool
                Sensitive:   bool
                /* ... */
```

## Framework

In the Framework, you set the same fields on the `schema.Attribute` implementation, with the same behavior.

```go
func (r *ThingResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
    resp.Schema = schema.Schema{
        /* ... */
        Attributes: map[string]schema.Attribute{
            "attribute_example": schema.XXXAttribute{
                Required:   bool
                Optional:   bool
                Computed:   bool
                Sensitive:  bool
                /* ... */
```

## Example

### SDKv2

The following example shows how the `example_attribute` attribute on the `exampleDataSource` data source is set to
be required with SDKv2.

```go
func exampleDataSource() *schema.Resource {
    return &schema.Resource{
        Schema: map[string]*schema.Schema{
            "example_attribute": {
                Required:   true,
                /* ... */
            },
            /* ... */
```

### Framework

The following example shows how the `example_attribute` attribute on the `exampleDataSource` data source is set
to be required with the Framework.

```go
func (d *exampleDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
    resp.Schema = schema.Schema{
        Attributes: map[string]schema.Attribute{
            "example_attribute": schema.StringAttribute{
                Required:   true,
                /* ... */
            },
            /* ... */
```
