Skip to content

Commit 5a17857

Browse files
committed
Migrate tfsdk package Config, Plan, and State into schema package
Reference: #76 These types are tightly coupled to Schema and Attribute handling and migrating them will allow for future enhancements with Attribute plan modifications and validations to reference these types without an import cycle.
1 parent b61fdeb commit 5a17857

File tree

7 files changed

+62
-61
lines changed

7 files changed

+62
-61
lines changed

tfsdk/config.go renamed to schema/config.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
package tfsdk
1+
package schema
22

33
import (
44
"context"
55
"fmt"
66

77
"github.com/hashicorp/terraform-plugin-framework/attr"
88
"github.com/hashicorp/terraform-plugin-framework/internal/reflect"
9-
"github.com/hashicorp/terraform-plugin-framework/schema"
109
"github.com/hashicorp/terraform-plugin-go/tftypes"
1110
)
1211

1312
// Config represents a Terraform config.
1413
type Config struct {
1514
Raw tftypes.Value
16-
Schema schema.Schema
15+
Schema Schema
1716
}
1817

1918
// Get populates the struct passed as `target` with the entire config.

tfsdk/plan.go renamed to schema/plan.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
package tfsdk
1+
package schema
22

33
import (
44
"context"
55
"fmt"
66

77
"github.com/hashicorp/terraform-plugin-framework/attr"
88
"github.com/hashicorp/terraform-plugin-framework/internal/reflect"
9-
"github.com/hashicorp/terraform-plugin-framework/schema"
109
"github.com/hashicorp/terraform-plugin-go/tftypes"
1110
)
1211

1312
// Plan represents a Terraform plan.
1413
type Plan struct {
1514
Raw tftypes.Value
16-
Schema schema.Schema
15+
Schema Schema
1716
}
1817

1918
// Get populates the struct passed as `target` with the entire plan.

tfsdk/state.go renamed to schema/state.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
package tfsdk
1+
package schema
22

33
import (
44
"context"
55
"fmt"
66

77
"github.com/hashicorp/terraform-plugin-framework/attr"
88
"github.com/hashicorp/terraform-plugin-framework/internal/reflect"
9-
"github.com/hashicorp/terraform-plugin-framework/schema"
109
"github.com/hashicorp/terraform-plugin-go/tftypes"
1110
)
1211

1312
// State represents a Terraform state.
1413
type State struct {
1514
Raw tftypes.Value
16-
Schema schema.Schema
15+
Schema Schema
1716
}
1817

1918
// Get populates the struct passed as `target` with the entire state.

tfsdk/state_test.go renamed to schema/state_test.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package tfsdk
1+
package schema
22

33
import (
44
"context"
@@ -7,16 +7,15 @@ import (
77

88
"github.com/google/go-cmp/cmp"
99
"github.com/hashicorp/terraform-plugin-framework/attr"
10-
"github.com/hashicorp/terraform-plugin-framework/schema"
1110
"github.com/hashicorp/terraform-plugin-framework/types"
1211
"github.com/hashicorp/terraform-plugin-go/tftypes"
1312
)
1413

1514
var allowAllUnexported = cmp.Exporter(func(reflect.Type) bool { return true })
1615

1716
// schema used for all tests
18-
var testSchema = schema.Schema{
19-
Attributes: map[string]schema.Attribute{
17+
var testSchema = Schema{
18+
Attributes: map[string]Attribute{
2019
"name": {
2120
Type: types.StringType,
2221
Required: true,
@@ -31,7 +30,7 @@ var testSchema = schema.Schema{
3130
Required: true,
3231
},
3332
"disks": {
34-
Attributes: schema.ListNestedAttributes(map[string]schema.Attribute{
33+
Attributes: ListNestedAttributes(map[string]Attribute{
3534
"id": {
3635
Type: types.StringType,
3736
Required: true,
@@ -40,12 +39,12 @@ var testSchema = schema.Schema{
4039
Type: types.BoolType,
4140
Optional: true,
4241
},
43-
}, schema.ListNestedAttributesOptions{}),
42+
}, ListNestedAttributesOptions{}),
4443
Optional: true,
4544
Computed: true,
4645
},
4746
"boot_disk": {
48-
Attributes: schema.SingleNestedAttributes(map[string]schema.Attribute{
47+
Attributes: SingleNestedAttributes(map[string]Attribute{
4948
"id": {
5049
Type: types.StringType,
5150
Required: true,

tfsdk/request.go

+18-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package tfsdk
22

3+
import (
4+
"github.com/hashicorp/terraform-plugin-framework/schema"
5+
)
6+
37
// ConfigureProviderRequest represents a request containing the values the user
48
// specified for the provider configuration block, along with other runtime
59
// information from Terraform or the Plugin SDK. An instance of this request
@@ -15,7 +19,7 @@ type ConfigureProviderRequest struct {
1519
// information should usually be persisted to the underlying type
1620
// that's implementing the Provider interface, for use in later
1721
// resource CRUD operations.
18-
Config Config
22+
Config schema.Config
1923
}
2024

2125
// CreateResourceRequest represents a request for the provider to create a
@@ -27,13 +31,13 @@ type CreateResourceRequest struct {
2731
// This configuration may contain unknown values if a user uses
2832
// interpolation or other functionality that would prevent Terraform
2933
// from knowing the value at request time.
30-
Config Config
34+
Config schema.Config
3135

3236
// Plan is the planned state for the resource.
33-
Plan Plan
37+
Plan schema.Plan
3438

3539
// ProviderMeta is metadata from the provider_meta block of the module.
36-
ProviderMeta Config
40+
ProviderMeta schema.Config
3741
}
3842

3943
// ReadResourceRequest represents a request for the provider to read a
@@ -43,10 +47,10 @@ type CreateResourceRequest struct {
4347
type ReadResourceRequest struct {
4448
// State is the current state of the resource prior to the Read
4549
// operation.
46-
State State
50+
State schema.State
4751

4852
// ProviderMeta is metadata from the provider_meta block of the module.
49-
ProviderMeta Config
53+
ProviderMeta schema.Config
5054
}
5155

5256
// UpdateResourceRequest represents a request for the provider to update a
@@ -58,17 +62,17 @@ type UpdateResourceRequest struct {
5862
// This configuration may contain unknown values if a user uses
5963
// interpolation or other functionality that would prevent Terraform
6064
// from knowing the value at request time.
61-
Config Config
65+
Config schema.Config
6266

6367
// Plan is the planned state for the resource.
64-
Plan Plan
68+
Plan schema.Plan
6569

6670
// State is the current state of the resource prior to the Update
6771
// operation.
68-
State State
72+
State schema.State
6973

7074
// ProviderMeta is metadata from the provider_meta block of the module.
71-
ProviderMeta Config
75+
ProviderMeta schema.Config
7276
}
7377

7478
// DeleteResourceRequest represents a request for the provider to delete a
@@ -77,10 +81,10 @@ type UpdateResourceRequest struct {
7781
type DeleteResourceRequest struct {
7882
// State is the current state of the resource prior to the Delete
7983
// operation.
80-
State State
84+
State schema.State
8185

8286
// ProviderMeta is metadata from the provider_meta block of the module.
83-
ProviderMeta Config
87+
ProviderMeta schema.Config
8488
}
8589

8690
// ReadDataSourceRequest represents a request for the provider to read a data
@@ -93,8 +97,8 @@ type ReadDataSourceRequest struct {
9397
// This configuration may contain unknown values if a user uses
9498
// interpolation or other functionality that would prevent Terraform
9599
// from knowing the value at request time.
96-
Config Config
100+
Config schema.Config
97101

98102
// ProviderMeta is metadata from the provider_meta block of the module.
99-
ProviderMeta Config
103+
ProviderMeta schema.Config
100104
}

tfsdk/response.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package tfsdk
22

33
import (
4+
"github.com/hashicorp/terraform-plugin-framework/schema"
45
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
56
"github.com/hashicorp/terraform-plugin-go/tftypes"
67
)
@@ -66,7 +67,7 @@ type CreateResourceResponse struct {
6667
// State is the state of the resource following the Create operation.
6768
// This field is pre-populated from CreateResourceRequest.Plan and
6869
// should be set during the resource's Create operation.
69-
State State
70+
State schema.State
7071

7172
// Diagnostics report errors or warnings related to creating the
7273
// resource. An empty slice indicates a successful operation with no
@@ -124,7 +125,7 @@ type ReadResourceResponse struct {
124125
// State is the state of the resource following the Read operation.
125126
// This field is pre-populated from ReadResourceRequest.State and
126127
// should be set during the resource's Read operation.
127-
State State
128+
State schema.State
128129

129130
// Diagnostics report errors or warnings related to reading the
130131
// resource. An empty slice indicates a successful operation with no
@@ -182,7 +183,7 @@ type UpdateResourceResponse struct {
182183
// State is the state of the resource following the Update operation.
183184
// This field is pre-populated from UpdateResourceRequest.Plan and
184185
// should be set during the resource's Update operation.
185-
State State
186+
State schema.State
186187

187188
// Diagnostics report errors or warnings related to updating the
188189
// resource. An empty slice indicates a successful operation with no
@@ -240,7 +241,7 @@ type DeleteResourceResponse struct {
240241
// State is the state of the resource following the Delete operation.
241242
// This field is pre-populated from UpdateResourceRequest.Plan and
242243
// should be set during the resource's Update operation.
243-
State State
244+
State schema.State
244245

245246
// Diagnostics report errors or warnings related to deleting the
246247
// resource. An empty slice indicates a successful operation with no
@@ -297,7 +298,7 @@ func (r *DeleteResourceResponse) AddAttributeError(attributePath *tftypes.Attrib
297298
type ReadDataSourceResponse struct {
298299
// State is the state of the data source following the Read operation.
299300
// This field should be set during the resource's Read operation.
300-
State State
301+
State schema.State
301302

302303
// Diagnostics report errors or warnings related to reading the data
303304
// source. An empty slice indicates a successful operation with no

0 commit comments

Comments
 (0)