Skip to content

Commit b69c145

Browse files
committed
Expand on validation interfaces
1 parent 3047b49 commit b69c145

File tree

2 files changed

+48
-6
lines changed

2 files changed

+48
-6
lines changed

resource/list.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ import (
1010
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
1111
)
1212

13+
// List represents an implementation of listing instances of a managed resource
14+
// This is the core interface for all list implementations.
15+
//
16+
// List implementations can optionally implement these additional concepts:
17+
//
18+
// - Configure: Include provider-level data or clients.
19+
// - Validation: Schema-based or entire configuration via
20+
// ListWithConfigValidators or ListWithValidateConfig.
1321
type List interface {
1422
Metadata(context.Context, MetadataRequest, *MetadataResponse)
1523
ListSchema(context.Context, SchemaRequest, SchemaResponse)
@@ -21,6 +29,11 @@ type ListWithConfigure interface {
2129
Configure(context.Context, ConfigureRequest, *ConfigureResponse)
2230
}
2331

32+
type ListWithConfigValidators interface {
33+
List
34+
ListConfigValidators(context.Context) []ListConfigValidator
35+
}
36+
2437
type ListWithValidateConfig interface {
2538
List
2639
ValidateListConfig(context.Context, ValidateListConfigRequest, *ValidateListConfigResponse)
@@ -42,10 +55,26 @@ type ListResult struct {
4255
Diagnostics diag.Diagnostics
4356
}
4457

58+
// ValidateListConfigRequest represents a request to validate the
59+
// configuration of a resource. An instance of this request struct is
60+
// supplied as an argument to the Resource ValidateListConfig receiver method
61+
// or automatically passed through to each ListConfigValidator.
4562
type ValidateListConfigRequest struct {
63+
// Config is the configuration the user supplied for the resource.
64+
//
65+
// This configuration may contain unknown values if a user uses
66+
// interpolation or other functionality that would prevent Terraform
67+
// from knowing the value at request time.
4668
Config tfsdk.Config
4769
}
4870

71+
// ValidateListConfigResponse represents a response to a
72+
// ValidateListConfigRequest. An instance of this response struct is
73+
// supplied as an argument to the Resource ValidateListConfig receiver method
74+
// or automatically passed through to each ListConfigValidator.
4975
type ValidateListConfigResponse struct {
76+
// Diagnostics report errors or warnings related to validating the resource
77+
// configuration. An empty slice indicates success, with no warnings or
78+
// errors generated.
5079
Diagnostics diag.Diagnostics
5180
}

resource/list_test.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ import (
1212
type ComputeInstance struct {
1313
}
1414

15-
func (c *ComputeInstance) Configure(_ context.Context, _ resource.ConfigureRequest, _ *resource.ConfigureResponse) {
16-
panic("not implemented")
15+
type ComputeInstanceWithValidateConfig struct {
16+
ComputeInstance
17+
}
18+
19+
type ComputeInstanceWithConfigValidators struct {
20+
ComputeInstance
1721
}
1822

19-
func (c *ComputeInstance) ValidateListConfig(_ context.Context, _ resource.ValidateListConfigRequest, _ *resource.ValidateListConfigResponse) {
23+
func (c *ComputeInstance) Configure(_ context.Context, _ resource.ConfigureRequest, _ *resource.ConfigureResponse) {
2024
panic("not implemented")
2125
}
2226

@@ -52,12 +56,21 @@ func (c *ComputeInstance) Delete(_ context.Context, _ resource.DeleteRequest, _
5256
panic("not implemented")
5357
}
5458

55-
// ExampleResource_listable demonstrates a resource.Resource that implements resource.List interfaces
56-
func ExampleResource_listable() {
59+
func (c *ComputeInstanceWithValidateConfig) ValidateListConfig(_ context.Context, _ resource.ValidateListConfigRequest, _ *resource.ValidateListConfigResponse) {
60+
panic("not implemented")
61+
}
62+
63+
func (c *ComputeInstanceWithConfigValidators) ListConfigValidators(_ context.Context) []resource.ListConfigValidator {
64+
panic("not implemented")
65+
}
5766

67+
// ExampleResource_listable demonstrates a resource.Resource that implements
68+
// resource.List interfaces.
69+
func ExampleResource_listable() {
5870
var _ resource.List = &ComputeInstance{}
5971
var _ resource.ListWithConfigure = &ComputeInstance{}
60-
var _ resource.ListWithValidateConfig = &ComputeInstance{}
72+
var _ resource.ListWithValidateConfig = &ComputeInstanceWithValidateConfig{}
73+
var _ resource.ListWithConfigValidators = &ComputeInstanceWithConfigValidators{}
6174

6275
var _ resource.Resource = &ComputeInstance{}
6376
var _ resource.ResourceWithConfigure = &ComputeInstance{}

0 commit comments

Comments
 (0)