Framework v6 provider schema attribute default

Just getting into terraform provider development, and my provider needs a boolean attribute, but I’d like it to default to false. Maybe I’m missing an import, but when I try to do something like:

func (p *myProvider) Schema(_ context.Context, _ provider.SchemaRequest, resp *provider.SchemaResponse) {
        resp.Schema = schema.Schema{
                Description: "A provider",
                Attributes: map[string]schema.Attribute{
                        ...
                        "modular": schema.BoolAttribute{
                                Description: "Description for a boolean option",
                                Optional: true,
                                Default:  booldefault.StaticBool(false),
                        },
                        ...

I’m getting an error:

unknown field Default in struct literal of type "github.com/hashicorp/terraform-plugin-framework/provider/schema".BoolAttribute (compiler MissingLitField)

Looking into the provider schema: terraform-plugin-framework/provider/schema/bool_attribute.go at main · hashicorp/terraform-plugin-framework · GitHub

There is not a way to set a default this way. I’m looking for a suggestion to set a default for a schema attribute for a provider. Thank you in advance!

I’m guessing that if it is not set, you can set the default in the Configure() of the provider, instead of AddAttributeError because it isn’t set.

        // modular defaults to false
        modular := false

        if !config.Modular.IsNull() {
                modular = config.Modular.ValueBool()
        }

Which is fine. I guess my confusion just comes from resource schema attributes having defaults, but provider schema attributes do not.

Indeed, provider schema attributes do not support Default, but I don’t think they need it.

You can tell whether the user set the attribute by checking the IsNull() method. If that comes up true, just do the default behavior. Your case is even simpler: Your default value is the same as the zero value for the underlying type (boolean), so you can just consult ValueBool() and get the expected value whether or practitioner set it or not.

Resource attributes are a different story. Those values get stored in state (this is the reason you must also set Computed: true), so the difference between null and a computed default value produce different outcomes in the state file.