diff --git a/.changelog/563.txt b/.changelog/563.txt new file mode 100644 index 000000000..062f92301 --- /dev/null +++ b/.changelog/563.txt @@ -0,0 +1,7 @@ +```release-note:note +tfsdk: The `Attribute`, `Block`, and `Schema` types have been deprecated. Use the similarly named types in the `datasource/schema`, `provider/schema`, and `resource/schema` packages instead. +``` + +```release-note:note +tfsdk: The `ListNestedAttributes`, `MapNestedAttributes`, `SetNestedAttributes`, and `SingleNestedAttributes` functions have been deprecated. Use the similarly named types in the `datasource/schema`, `provider/schema`, and `resource/schema` packages instead. +``` diff --git a/.golangci.yml b/.golangci.yml index b9a329c4d..98674333f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,4 +1,12 @@ issues: + # Temporary rules for unit testing until tfsdk.Schema is removed. + exclude-rules: + - linters: + - staticcheck + text: 'SA1019: tfsdk.(Attribute|Block|Schema) is deprecated' + - linters: + - staticcheck + text: 'SA1019: tfsdk.(List|Map|Set|Single)NestedAttributes is deprecated' max-per-linter: 0 max-same-issues: 0 diff --git a/internal/fwserver/server_planresourcechange.go b/internal/fwserver/server_planresourcechange.go index 4c63d6ce7..bc8aff65e 100644 --- a/internal/fwserver/server_planresourcechange.go +++ b/internal/fwserver/server_planresourcechange.go @@ -285,13 +285,13 @@ func MarkComputedNilsAsUnknown(ctx context.Context, config tftypes.Value, resour attribute, err := resourceSchema.AttributeAtTerraformPath(ctx, path) if err != nil { - if errors.Is(err, tfsdk.ErrPathInsideAtomicAttribute) { + if errors.Is(err, fwschema.ErrPathInsideAtomicAttribute) { // ignore attributes/elements inside schema.Attributes, they have no schema of their own logging.FrameworkTrace(ctx, "attribute is a non-schema attribute, not marking unknown") return val, nil } - if errors.Is(err, tfsdk.ErrPathIsBlock) { + if errors.Is(err, fwschema.ErrPathIsBlock) { // ignore blocks, they do not have a computed field logging.FrameworkTrace(ctx, "attribute is a block, not marking unknown") return val, nil diff --git a/resource/plan_modifiers.go b/resource/plan_modifiers.go index daf28edfa..03653b3b7 100644 --- a/resource/plan_modifiers.go +++ b/resource/plan_modifiers.go @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/internal/fwschema" "github.com/hashicorp/terraform-plugin-framework/internal/logging" "github.com/hashicorp/terraform-plugin-framework/internal/totftypes" "github.com/hashicorp/terraform-plugin-framework/path" @@ -104,7 +105,7 @@ func (r requiresReplaceModifier) Modify(ctx context.Context, req tfsdk.ModifyAtt // Path may lead to block instead of attribute. Blocks cannot be Computed. // If ErrPathIsBlock, attrSchema.Computed will still be false later. - if err != nil && !errors.Is(err, tfsdk.ErrPathIsBlock) { + if err != nil && !errors.Is(err, fwschema.ErrPathIsBlock) { resp.Diagnostics.AddAttributeError(req.AttributePath, "Error finding attribute schema", fmt.Sprintf("An unexpected error was encountered retrieving the schema for this attribute. This is always a bug in the provider.\n\nError: %s", err), @@ -249,7 +250,7 @@ func (r requiresReplaceIfModifier) Modify(ctx context.Context, req tfsdk.ModifyA // Path may lead to block instead of attribute. Blocks cannot be Computed. // If ErrPathIsBlock, attrSchema.Computed will still be false later. - if err != nil && !errors.Is(err, tfsdk.ErrPathIsBlock) { + if err != nil && !errors.Is(err, fwschema.ErrPathIsBlock) { resp.Diagnostics.AddAttributeError(req.AttributePath, "Error finding attribute schema", fmt.Sprintf("An unexpected error was encountered retrieving the schema for this attribute. This is always a bug in the provider.\n\nError: %s", err), diff --git a/tfsdk/attribute.go b/tfsdk/attribute.go index b18c5967e..464ccaceb 100644 --- a/tfsdk/attribute.go +++ b/tfsdk/attribute.go @@ -20,6 +20,11 @@ var ( // Attribute defines the constraints and behaviors of a single value field in a // schema. Attributes are the fields that show up in Terraform state files and // can be used in configuration files. +// +// Deprecated: Use datasource/schema.Attribute, provider/schema.Attribute, or +// resource/schema.Attribute instead. This can be switched by using the +// datasource/schema.Schema, provider/schema.Schema, or resource/schema.Schema +// types. type Attribute struct { // Type indicates what kind of attribute this is. You'll most likely // want to use one of the types in the types package. diff --git a/tfsdk/block.go b/tfsdk/block.go index 3f30fa5a9..f169714df 100644 --- a/tfsdk/block.go +++ b/tfsdk/block.go @@ -22,6 +22,11 @@ var _ fwschema.Block = Block{} // // The NestingMode field must be set or a runtime error will be raised by the // framework when fetching the schema. +// +// Deprecated: Use datasource/schema.Block, provider/schema.Block, or +// resource/schema.Block instead. This can be switched by using the +// datasource/schema.Schema, provider/schema.Schema, or resource/schema.Schema +// types. type Block struct { // Attributes are value fields inside the block. This map of attributes // behaves exactly like the map of attributes on the Schema type. diff --git a/tfsdk/doc.go b/tfsdk/doc.go index 72f057bbf..5711119d7 100644 --- a/tfsdk/doc.go +++ b/tfsdk/doc.go @@ -1,2 +1,2 @@ -// Package tfsdk contains core framework functionality for schemas and schema data. +// Package tfsdk contains core framework functionality for schema data. package tfsdk diff --git a/tfsdk/nested_attributes.go b/tfsdk/nested_attributes.go index 48bf792f2..4a79ca353 100644 --- a/tfsdk/nested_attributes.go +++ b/tfsdk/nested_attributes.go @@ -7,6 +7,11 @@ import ( // ListNestedAttributes nests `attributes` under another attribute, allowing // multiple instances of that group of attributes to appear in the // configuration. +// +// Deprecated: Use datasource/schema.ListNestedAttribute, +// provider/schema.ListNestedAttribute, or resource/schema.ListNestedAttribute +// instead. This can be switched by using the datasource/schema.Schema, +// provider/schema.Schema, or resource/schema.Schema types. func ListNestedAttributes(attributes map[string]Attribute) fwschema.NestedAttributes { return fwschema.ListNestedAttributes{ UnderlyingAttributes: schemaAttributes(attributes), @@ -17,6 +22,11 @@ func ListNestedAttributes(attributes map[string]Attribute) fwschema.NestedAttrib // multiple instances of that group of attributes to appear in the // configuration. Each group will need to be associated with a unique string by // the user. +// +// Deprecated: Use datasource/schema.MapNestedAttribute, +// provider/schema.MapNestedAttribute, or resource/schema.MapNestedAttribute +// instead. This can be switched by using the datasource/schema.Schema, +// provider/schema.Schema, or resource/schema.Schema types. func MapNestedAttributes(attributes map[string]Attribute) fwschema.NestedAttributes { return fwschema.MapNestedAttributes{ UnderlyingAttributes: schemaAttributes(attributes), @@ -26,6 +36,11 @@ func MapNestedAttributes(attributes map[string]Attribute) fwschema.NestedAttribu // SetNestedAttributes nests `attributes` under another attribute, allowing // multiple instances of that group of attributes to appear in the // configuration, while requiring each group of values be unique. +// +// Deprecated: Use datasource/schema.SetNestedAttribute, +// provider/schema.SetNestedAttribute, or resource/schema.SetNestedAttribute +// instead. This can be switched by using the datasource/schema.Schema, +// provider/schema.Schema, or resource/schema.Schema types. func SetNestedAttributes(attributes map[string]Attribute) fwschema.NestedAttributes { return fwschema.SetNestedAttributes{ UnderlyingAttributes: schemaAttributes(attributes), @@ -35,6 +50,11 @@ func SetNestedAttributes(attributes map[string]Attribute) fwschema.NestedAttribu // SingleNestedAttributes nests `attributes` under another attribute, only // allowing one instance of that group of attributes to appear in the // configuration. +// +// Deprecated: Use datasource/schema.SingleNestedAttribute, +// provider/schema.SingleNestedAttribute, or resource/schema.SingleNestedAttribute +// instead. This can be switched by using the datasource/schema.Schema, +// provider/schema.Schema, or resource/schema.Schema types. func SingleNestedAttributes(attributes map[string]Attribute) fwschema.NestedAttributes { return fwschema.SingleNestedAttributes{ UnderlyingAttributes: schemaAttributes(attributes), diff --git a/tfsdk/schema.go b/tfsdk/schema.go index 848292f13..d11221da8 100644 --- a/tfsdk/schema.go +++ b/tfsdk/schema.go @@ -15,10 +15,18 @@ var ( // on a path that doesn't have a schema associated with it, because // it's an element, attribute, or block of a complex type, not a nested // attribute. + // + // Deprecated: This error value was intended for internal usage and will + // be removed in a future version. If you have a use case for this, + // please create a GitHub issue. ErrPathInsideAtomicAttribute = fwschema.ErrPathInsideAtomicAttribute // ErrPathIsBlock is used with AttributeAtPath is called on a path is a // block, not an attribute. Use blockAtPath on the path instead. + // + // Deprecated: This error value was intended for internal usage and will + // be removed in a future version. If you have a use case for this, + // please create a GitHub issue. ErrPathIsBlock = fwschema.ErrPathIsBlock ) @@ -28,6 +36,11 @@ var _ fwschema.Schema = Schema{} // Schema is used to define the shape of practitioner-provider information, // like resources, data sources, and providers. Think of it as a type // definition, but for Terraform. +// +// Deprecated: Use datasource/schema.Schema, provider/schema.Schema, or +// resource/schema.Schema instead. This can be switched by using the +// datasource.DataSource, provider.Provider, or resource.Resource interface +// Schema method. type Schema struct { // Attributes are value fields inside the resource, provider, or data // source that the schema is defining. The map key should be the name