Framework Migration: Block with Computed Field and Element Attribute with Default Field

map[string]*schema.Schema{
    "example": {
        Type:     schema.TypeList,
        Computed: true,
        Elem: &schema.Resource{
            Schema: map[string]*schema.Schema{
                "nested_example": {
                        Type:        schema.TypeString,
                        Computed:    true,
                        Default: "something"
                        /* ... */

So with protocol 5, how can I migrate it to be framework? Do I have to implement a custom type for that?

Hi @zliang-akamai,
Default values in the framework are set on attributes that are both computed and optional and used when the attribute is not set in the configuration. Since this is an attribute in a computed-only block, you do not need to define a default value. You can set the value in a resource-level PlanModifier() or in the Create() method depending on whether you need the value set during the plan or apply step.

For the rest of the block, you can follow the migration steps for computed-only blocks in the migration guide.

Thanks for the response! Sorry about the previous bad example, I shouldn’t put Computed inside the attribute with a Default field. How about an attribute with Optional field and default? Like this real example I got:

SDKv2:

var resourceSchema = map[string]*schema.Schema{
"helpers": {
		Type:        schema.TypeList,
		Elem:        &schema.Resource{Schema: helpersSchema},
		Optional:    true,
		Computed:    true,
		Description: "Helpers enabled when booting to this Linode Config.",
	}
}
var helpersSchema = map[string]*schema.Schema{
	"some_attr": {
		Type:        schema.TypeBool,
		Description: "Populates the /dev directory early during boot without udev.",
		Optional:    true,
		Default:     true,
	},
	// some other attributes...
}

Framework:

"helpers": schema.ListAttribute{
			ElementType:types.ObjectType{
				AttrTypes: map[string]attr.Type {
					"some_attr": types.BoolType, // I can't put default value here...
					// ...
				},
			},
			Optional:    true,
			Computed:    true,
			Description: "Helpers enabled when booting to this Linode Config.",
		},

The framework code that you have is specifically for computed-only Blocks, to migrate blocks that have optional fields you can refer to the Blocks page in the migration guide.

So to rewrite your example in the framework:

Blocks: map[string]schema.Block{
			"helpers": schema.ListNestedBlock{
				NestedObject: schema.NestedBlockObject{
					Attributes: map[string]schema.Attribute{
						"some_attr": schema.BoolAttribute{
							Optional: true,
							Computed: true,
							Default:  booldefault.StaticBool(false),
						},
						//...
					},
				},
				Description: "Helpers enabled when booting to this Linode Config.",
			},
		}

Thank you! But will the ListNestedBlock named "helpers" be both Optional and Computed in this case to align with SDKv2 provider behavior? It looks like that making them as a block will make it to be a Required attribute.

The "helpers" block should have the same behavior as an SDKv2 Computed and Optional block. The ListNestedBlock by default is optional unless you add a listvalidator.isRequired() validator to make it required. And the individual nested attributes that are set as Computed and Optional should have the same behavior as their SDKv2 counterparts.

Hi @SBGoods

Our team tried migrating to blocks but found its behavior doesn’t align with computed