Attribute Types
An attribute either contains a primitive type, such as an integer or a string, or contains other attributes. Attributes
that contain other attributes are referred to as nested attributes, and are implemented by populating the
NestedAttributes
field on the tfsdk.Attribute
struct. Refer to
Schemas - Attributes in the Framework documentation for details.
This page explains how to migrate a primitive attribute from SDKv2 to the plugin Framework. For an example of migrating a nested block to a nested attribute, refer to Providers in this guide.
SDKv2
In SDKv2, attribute types are defined by the Type
field on the attribute's schema.Schema
struct.
Framework
In the Framework, you set your attribute's type with the Type
field on your attribute's tfsdk.Attribute
struct.
Migration Notes
Remember the following differences between SDKv2 and the Framework when completing the migration.
- In the Framework, an
Attribute
struct has either theType
orAttributes
field defined. TheType
field is set to a primitive type such as an integer or string, and you use theAttributes
field forNestedAttributes
. Refer to Providers for an example of using a single nested attribute. Nested attributes are also described in more detail on the Schemas page in the Framework documentation.
Example
The following examples show how to migrate portions of the http provider.
For a complete example, clone the
terraform-provider-http
repository and compare the data_source.go
file in
v2.2.0
and the data_source_http.go
file in
v3.0.1.
SDKv2
The following example from the data_source.go
file shows the implementation of the type field of the url
attribute
for the http
data source with SDKv2.
Framework
The following example from the data_source_http.go
file shows how the type of the url
attribute for the http
data
source is defined with the Framework after the migration.
The following examples show how to migrate portions of the tls provider.
For a complete example, clone the
terraform-provider-tls
repository and compare the common_cert.go
file in
v3.4.0
and the resource_cert_request.go
file in
v4.0.1.
SDKv2
The following example from the common_cert.go
file shows the implementation of the type field of the dns_names
attribute with SDKv2.
Framework
The following example from the data_source_http.go
file shows how the type of the url
attribute for the http
data
source is defined with the Framework after the migration.