Skip to content

Commit f8aa962

Browse files
committed
resource+tfsdk: Remove tfsdk package schema types and functions
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
1 parent 5376f82 commit f8aa962

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1001
-8576
lines changed

.changelog/pending.txt

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
```release-note:breaking-change
2+
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()`
3+
```
4+
5+
```release-note:breaking-change
6+
resource: The `RequiresReplaceIf()` plan modifier has been removed. Use a type-specific plan modifier instead, such as `resource/schema/stringplanmodifier.RequiresReplaceIf()`
7+
```
8+
9+
```release-note:breaking-change
10+
resource: The `Resource` type `GetSchema` method has been removed. Use the `Schema` method instead.
11+
```
12+
13+
```release-note:breaking-change
14+
resource: The `UseStateForUnknown()` plan modifier has been removed. Use a type-specific plan modifier instead, such as `resource/schema/stringplanmodifier.UseStateForUnknown()`
15+
```
16+
17+
```release-note:breaking-change
18+
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.
19+
```
20+
21+
```release-note:breaking-change
22+
tfsdk: The `AttributePlanModifier` interface has been removed. Use the type-specific plan modifier interfaces in the `resource/schema/planmodifier` package instead.
23+
```
24+
25+
```release-note:breaking-change
26+
tfsdk: The `AttributeValidator` interface has been removed. Use the type-specific validator interfaces in the `schema/validator` package instead.
27+
```
28+
29+
```release-note:breaking-change
30+
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.
31+
```

.golangci.yml

-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
11
issues:
2-
# Temporary rules for unit testing until tfsdk.Schema is removed.
3-
exclude-rules:
4-
- linters:
5-
- staticcheck
6-
text: 'SA1019: tfsdk.(Attribute|Block|Schema) is deprecated'
7-
- linters:
8-
- staticcheck
9-
text: 'SA1019: tfsdk.(List|Map|Set|Single)NestedAttributes is deprecated'
102
max-per-linter: 0
113
max-same-issues: 0
124

datasource/data_source.go

+5-27
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,24 @@ package datasource
22

33
import (
44
"context"
5-
6-
"github.com/hashicorp/terraform-plugin-framework/diag"
7-
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
85
)
96

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

20+
// Schema should return the schema for this data source.
21+
Schema(context.Context, SchemaRequest, *SchemaResponse)
22+
2523
// Read is called when the provider must read data source values in
2624
// order to update state. Config values should be read from the
2725
// ReadRequest and new state values set on the ReadResponse.
@@ -59,26 +57,6 @@ type DataSourceWithConfigValidators interface {
5957
ConfigValidators(context.Context) []ConfigValidator
6058
}
6159

62-
// DataSourceWithGetSchema is a temporary interface type that extends
63-
// DataSource to include the deprecated GetSchema method.
64-
type DataSourceWithGetSchema interface {
65-
DataSource
66-
67-
// GetSchema returns the schema for this data source.
68-
//
69-
// Deprecated: Use Schema method instead.
70-
GetSchema(context.Context) (tfsdk.Schema, diag.Diagnostics)
71-
}
72-
73-
// DataSourceWithSchema is a temporary interface type that extends
74-
// DataSource to include the new Schema method.
75-
type DataSourceWithSchema interface {
76-
DataSource
77-
78-
// Schema should return the schema for this data source.
79-
Schema(context.Context, SchemaRequest, *SchemaResponse)
80-
}
81-
8260
// DataSourceWithValidateConfig is an interface type that extends DataSource to include imperative validation.
8361
//
8462
// Declaring validation using this methodology simplifies one-off
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package fwschema
2+
3+
// NestingMode is an enum type of the ways nested attributes can be nested in
4+
// an attribute. They can be a list, a set, a map (with string
5+
// keys), or they can be nested directly, like an object.
6+
type NestingMode uint8
7+
8+
const (
9+
// NestingModeUnknown is an invalid nesting mode, used to catch when a
10+
// nesting mode is expected and not set.
11+
NestingModeUnknown NestingMode = 0
12+
13+
// NestingModeSingle is for attributes that represent a struct or
14+
// object, a single instance of those attributes directly nested under
15+
// another attribute.
16+
NestingModeSingle NestingMode = 1
17+
18+
// NestingModeList is for attributes that represent a list of objects,
19+
// with multiple instances of those attributes nested inside a list
20+
// under another attribute.
21+
NestingModeList NestingMode = 2
22+
23+
// NestingModeSet is for attributes that represent a set of objects,
24+
// with multiple, unique instances of those attributes nested inside a
25+
// set under another attribute.
26+
NestingModeSet NestingMode = 3
27+
28+
// NestingModeMap is for attributes that represent a map of objects,
29+
// with multiple instances of those attributes, each associated with a
30+
// unique string key, nested inside a map under another attribute.
31+
NestingModeMap NestingMode = 4
32+
)

internal/fwschema/fwxschema/attribute_plan_modification.go

-14
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,8 @@ package fwxschema
33
import (
44
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
55
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
6-
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
76
)
87

9-
// AttributeWithPlanModifiers is an optional interface on Attribute which enables
10-
// plan modification support.
11-
type AttributeWithPlanModifiers interface {
12-
// Implementations should include the fwschema.Attribute interface methods
13-
// for proper attribute handling.
14-
fwschema.Attribute
15-
16-
// GetPlanModifiers should return a list of attribute-based plan modifiers.
17-
// This is named differently than PlanModifiers to prevent a conflict with
18-
// the tfsdk.Attribute field name.
19-
GetPlanModifiers() tfsdk.AttributePlanModifiers
20-
}
21-
228
// AttributeWithBoolPlanModifiers is an optional interface on Attribute which
239
// enables Bool plan modifier support.
2410
type AttributeWithBoolPlanModifiers interface {

internal/fwschema/fwxschema/attribute_validation.go

-14
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,8 @@ package fwxschema
33
import (
44
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
55
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
6-
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
76
)
87

9-
// AttributeWithValidators is an optional interface on Attribute which enables
10-
// validation support.
11-
type AttributeWithValidators interface {
12-
// Implementations should include the fwschema.Attribute interface methods
13-
// for proper attribute handling.
14-
fwschema.Attribute
15-
16-
// GetValidators should return a list of attribute-based validators. This
17-
// is named differently than PlanModifiers to prevent a conflict with the
18-
// tfsdk.Attribute field name.
19-
GetValidators() []tfsdk.AttributeValidator
20-
}
21-
228
// AttributeWithBoolValidators is an optional interface on Attribute which
239
// enables Bool validation support.
2410
type AttributeWithBoolValidators interface {

internal/fwschema/fwxschema/block_plan_modification.go

-14
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,8 @@ package fwxschema
33
import (
44
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
55
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
6-
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
76
)
87

9-
// BlockWithPlanModifiers is an optional interface on Block which enables
10-
// plan modification support.
11-
type BlockWithPlanModifiers interface {
12-
// Implementations should include the fwschema.Block interface methods
13-
// for proper block handling.
14-
fwschema.Block
15-
16-
// GetPlanModifiers should return a list of attribute-based plan modifiers.
17-
// This is named differently than PlanModifiers to prevent a conflict with
18-
// the tfsdk.Block field name.
19-
GetPlanModifiers() tfsdk.AttributePlanModifiers
20-
}
21-
228
// BlockWithListPlanModifiers is an optional interface on Block which
239
// enables List plan modifier support.
2410
type BlockWithListPlanModifiers interface {

internal/fwschema/fwxschema/block_validation.go

-14
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,8 @@ package fwxschema
33
import (
44
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
55
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
6-
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
76
)
87

9-
// BlockWithValidators is an optional interface on Block which enables
10-
// validation support.
11-
type BlockWithValidators interface {
12-
// Implementations should include the fwschema.Block interface methods
13-
// for proper block handling.
14-
fwschema.Block
15-
16-
// GetValidators should return a list of attribute-based validators. This
17-
// is named differently than Validators to prevent a conflict with the
18-
// tfsdk.Block field name.
19-
GetValidators() []tfsdk.AttributeValidator
20-
}
21-
228
// BlockWithListValidators is an optional interface on Block which
239
// enables List validation support.
2410
type BlockWithListValidators interface {

0 commit comments

Comments
 (0)