A Terraform schema defines the parameters, attributes, and configuration values exposed by a provider, resource, or data source. It specifies types, required or computed status, defaults, and documentation. section 12.3.1
Required, optional, and computed settings distinguish user-supplied values from values a provider may generate. Computed values may be unknown during planning. section 12.5.1
Listing 12.3 Schema example
func (p *MastodonProvider) Schema(ctx context.Context, req
provider.SchemaRequest, resp *provider.SchemaResponse) { #1
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{ #2
"host": schema.StringAttribute{ #3
MarkdownDescription: "Mastodon host to connect to.",
Optional: true,
Default: stringdefault.StaticString(
"mastodon.social"), #4
},
"email": schema.StringAttribute{
MarkdownDescription: "Username to connect to the server as.",
Optional: true,
DeprecationMessage: "Use access token instead.", #5
},
"password": schema.StringAttribute{
MarkdownDescription: "Password to use for connecting to the
server.",
Optional: true,
Sensitive: true, #6
DeprecationMessage: "Use access token instead.",
},
"access_token": schema.StringAttribute{
MarkdownDescription: "Password to use for connecting to the
server.",
Optional: true,
Sensitive: true,
},
},
}
}
#1 Schemas are defined in their own functions.
#2 Schemas are maps of schema attributes.
#3 All schemas have to map to a type, such as String.
#4 Schemas can have default values.
#5 It’s possible to mark an attribute as deprecated.
#6 Sensitive attributes are filtered out from logs.
See a provider schema with typed attributes, descriptions, an optional host default, and a deprecation message. section 12.3.1
Mastodon account lookup
A data source schema can accept an account name and define computed attributes such as display name, note, and account status. section 12.5.1











































