Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tfsdk: Deprecate Attribute, Block, and Schema types #563

Merged
merged 3 commits into from Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions .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.
```
8 changes: 8 additions & 0 deletions .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

Expand Down
4 changes: 2 additions & 2 deletions internal/fwserver/server_planresourcechange.go
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions resource/plan_modifiers.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
5 changes: 5 additions & 0 deletions tfsdk/attribute.go
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions tfsdk/block.go
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion 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
20 changes: 20 additions & 0 deletions tfsdk/nested_attributes.go
Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand Down
13 changes: 13 additions & 0 deletions tfsdk/schema.go
Expand Up @@ -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
)

Expand All @@ -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
Expand Down