Skip to content

Commit

Permalink
resource+tfsdk: Remove tfsdk package schema types and functions
Browse files Browse the repository at this point in the history
Reference: #132
Reference: #326
Reference: #491

Refer to the following pull request descriptions for migration information about migrating to the split schema packages:

- `datasource/schema`: #546
- `provider/schema`: #553
- `resource/schema`: #558
- `provider/metaschema`: #562
  • Loading branch information
bflad committed Dec 13, 2022
1 parent 085f2f9 commit 67822bb
Show file tree
Hide file tree
Showing 51 changed files with 1,001 additions and 8,576 deletions.
31 changes: 31 additions & 0 deletions .changelog/pending.txt
@@ -0,0 +1,31 @@
```release-note:breaking-change
resource: The `RequiresReplace()` plan modifier has been removed. Use a type-specific plan modifier instead, such as `resource/schema/stringplanmodifier.RequiresReplace()` or `resource/schema/stringplanmodifier.RequiresReplaceIfConfigured()`
```

```release-note:breaking-change
resource: The `RequiresReplaceIf()` plan modifier has been removed. Use a type-specific plan modifier instead, such as `resource/schema/stringplanmodifier.RequiresReplaceIf()`
```

```release-note:breaking-change
resource: The `Resource` type `GetSchema` method has been removed. Use the `Schema` method instead.
```

```release-note:breaking-change
resource: The `UseStateForUnknown()` plan modifier has been removed. Use a type-specific plan modifier instead, such as `resource/schema/stringplanmodifier.UseStateForUnknown()`
```

```release-note:breaking-change
tfsdk: The `Attribute`, `Block`, and `Schema` types have been removed. Use the similarly named types in the `datasource/schema`, `provider/schema`, and `resource/schema` packages instead.
```

```release-note:breaking-change
tfsdk: The `AttributePlanModifier` interface has been removed. Use the type-specific plan modifier interfaces in the `resource/schema/planmodifier` package instead.
```

```release-note:breaking-change
tfsdk: The `AttributeValidator` interface has been removed. Use the type-specific validator interfaces in the `schema/validator` package instead.
```

```release-note:breaking-change
tfsdk: The `ListNestedAttributes`, `MapNestedAttributes`, `SetNestedAttributes`, and `SingleNestedAttributes` functions have been removed. Use the similarly named types in the `datasource/schema`, `provider/schema`, and `resource/schema` packages instead.
```
8 changes: 0 additions & 8 deletions .golangci.yml
@@ -1,12 +1,4 @@
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
32 changes: 5 additions & 27 deletions datasource/data_source.go
Expand Up @@ -2,26 +2,24 @@ package datasource

import (
"context"

"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
)

// DataSource represents an instance of a data source type. This is the core
// interface that all data sources must implement. Data sources must also
// implement the Schema method or the deprecated GetSchema method. The Schema
// method will be required in a future version.
// interface that all data sources must implement.
//
// Data sources can optionally implement these additional concepts:
//
// - Configure: Include provider-level data or clients.
// - Validation: Schema-based via tfsdk.Attribute or entire configuration
// - Validation: Schema-based or entire configuration
// via DataSourceWithConfigValidators or DataSourceWithValidateConfig.
type DataSource interface {
// Metadata should return the full name of the data source, such as
// examplecloud_thing.
Metadata(context.Context, MetadataRequest, *MetadataResponse)

// Schema should return the schema for this data source.
Schema(context.Context, SchemaRequest, *SchemaResponse)

// Read is called when the provider must read data source values in
// order to update state. Config values should be read from the
// ReadRequest and new state values set on the ReadResponse.
Expand Down Expand Up @@ -59,26 +57,6 @@ type DataSourceWithConfigValidators interface {
ConfigValidators(context.Context) []ConfigValidator
}

// DataSourceWithGetSchema is a temporary interface type that extends
// DataSource to include the deprecated GetSchema method.
type DataSourceWithGetSchema interface {
DataSource

// GetSchema returns the schema for this data source.
//
// Deprecated: Use Schema method instead.
GetSchema(context.Context) (tfsdk.Schema, diag.Diagnostics)
}

// DataSourceWithSchema is a temporary interface type that extends
// DataSource to include the new Schema method.
type DataSourceWithSchema interface {
DataSource

// Schema should return the schema for this data source.
Schema(context.Context, SchemaRequest, *SchemaResponse)
}

// DataSourceWithValidateConfig is an interface type that extends DataSource to include imperative validation.
//
// Declaring validation using this methodology simplifies one-off
Expand Down
32 changes: 32 additions & 0 deletions internal/fwschema/attribute_nesting_mode.go
@@ -0,0 +1,32 @@
package fwschema

// NestingMode is an enum type of the ways nested attributes can be nested in
// an attribute. They can be a list, a set, a map (with string
// keys), or they can be nested directly, like an object.
type NestingMode uint8

const (
// NestingModeUnknown is an invalid nesting mode, used to catch when a
// nesting mode is expected and not set.
NestingModeUnknown NestingMode = 0

// NestingModeSingle is for attributes that represent a struct or
// object, a single instance of those attributes directly nested under
// another attribute.
NestingModeSingle NestingMode = 1

// NestingModeList is for attributes that represent a list of objects,
// with multiple instances of those attributes nested inside a list
// under another attribute.
NestingModeList NestingMode = 2

// NestingModeSet is for attributes that represent a set of objects,
// with multiple, unique instances of those attributes nested inside a
// set under another attribute.
NestingModeSet NestingMode = 3

// NestingModeMap is for attributes that represent a map of objects,
// with multiple instances of those attributes, each associated with a
// unique string key, nested inside a map under another attribute.
NestingModeMap NestingMode = 4
)
14 changes: 0 additions & 14 deletions internal/fwschema/fwxschema/attribute_plan_modification.go
Expand Up @@ -3,22 +3,8 @@ package fwxschema
import (
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
)

// AttributeWithPlanModifiers is an optional interface on Attribute which enables
// plan modification support.
type AttributeWithPlanModifiers interface {
// Implementations should include the fwschema.Attribute interface methods
// for proper attribute handling.
fwschema.Attribute

// GetPlanModifiers should return a list of attribute-based plan modifiers.
// This is named differently than PlanModifiers to prevent a conflict with
// the tfsdk.Attribute field name.
GetPlanModifiers() tfsdk.AttributePlanModifiers
}

// AttributeWithBoolPlanModifiers is an optional interface on Attribute which
// enables Bool plan modifier support.
type AttributeWithBoolPlanModifiers interface {
Expand Down
14 changes: 0 additions & 14 deletions internal/fwschema/fwxschema/attribute_validation.go
Expand Up @@ -3,22 +3,8 @@ package fwxschema
import (
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
)

// AttributeWithValidators is an optional interface on Attribute which enables
// validation support.
type AttributeWithValidators interface {
// Implementations should include the fwschema.Attribute interface methods
// for proper attribute handling.
fwschema.Attribute

// GetValidators should return a list of attribute-based validators. This
// is named differently than PlanModifiers to prevent a conflict with the
// tfsdk.Attribute field name.
GetValidators() []tfsdk.AttributeValidator
}

// AttributeWithBoolValidators is an optional interface on Attribute which
// enables Bool validation support.
type AttributeWithBoolValidators interface {
Expand Down
14 changes: 0 additions & 14 deletions internal/fwschema/fwxschema/block_plan_modification.go
Expand Up @@ -3,22 +3,8 @@ package fwxschema
import (
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
)

// BlockWithPlanModifiers is an optional interface on Block which enables
// plan modification support.
type BlockWithPlanModifiers interface {
// Implementations should include the fwschema.Block interface methods
// for proper block handling.
fwschema.Block

// GetPlanModifiers should return a list of attribute-based plan modifiers.
// This is named differently than PlanModifiers to prevent a conflict with
// the tfsdk.Block field name.
GetPlanModifiers() tfsdk.AttributePlanModifiers
}

// BlockWithListPlanModifiers is an optional interface on Block which
// enables List plan modifier support.
type BlockWithListPlanModifiers interface {
Expand Down
14 changes: 0 additions & 14 deletions internal/fwschema/fwxschema/block_validation.go
Expand Up @@ -3,22 +3,8 @@ package fwxschema
import (
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
)

// BlockWithValidators is an optional interface on Block which enables
// validation support.
type BlockWithValidators interface {
// Implementations should include the fwschema.Block interface methods
// for proper block handling.
fwschema.Block

// GetValidators should return a list of attribute-based validators. This
// is named differently than Validators to prevent a conflict with the
// tfsdk.Block field name.
GetValidators() []tfsdk.AttributeValidator
}

// BlockWithListValidators is an optional interface on Block which
// enables List validation support.
type BlockWithListValidators interface {
Expand Down

0 comments on commit 67822bb

Please sign in to comment.