Terraform
- Plugin Framework
- v1.16.x (latest)
- No versions of this document exist before v1.15.x. Click below to redirect to the version homepage.
- v1.15.x
- v1.14.x
- v1.13.x
- v1.12.x
- v1.11.x
- v1.10.x
- v1.9.x
- v1.8.x
- v1.7.x
- v1.6.x
- v1.5.x
- v1.4.x
- v1.3.x
- v1.2.x
- v1.1.x
- v0.17.x
- v0.16.x
- v0.15.x
- v0.14.x
- v0.13.x
- v0.12.x
- v0.11.x
- v0.10.x
- v0.9.x
- v0.8.x
- v0.7.x
Attribute Fields
A subset of attribute fields, such as required, optional, computed, or sensitive, define attribute behavior as boolean flags. Refer to Schemas - Attributes in the Framework documentation for details.
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.
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.
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.
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.
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,
/* ... */
},
/* ... */