-
Notifications
You must be signed in to change notification settings - Fork 97
tfsdk: Initial support for Attribute, Data Source, Provider, and Resource validation #75
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
Changes from 1 commit
5efc431
40f8848
68a4d7d
c0a1fcd
209de76
4be5375
bffb3f6
572ee67
c31f079
3605ca8
3371b54
57d574c
895901e
3517d8d
faa5afb
ee6ea5d
a3d747c
1397315
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package tfsdk | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
// DataSourceConfigValidator describes reusable DataSource configuration validation functionality. | ||
type DataSourceConfigValidator interface { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hot take: is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm certainly amenable to updating the name, I'm just not sure if there's any concerns with keeping the names and types relatively close to the RPCs similar to as has been done elsewhere. Should there be any future other implementations with differing semantics, it could be weird to have |
||
// Description describes the validation in plain text formatting. | ||
bflad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Description(context.Context) string | ||
paddycarver marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// MarkdownDescription describes the validation in Markdown formatting. | ||
MarkdownDescription(context.Context) string | ||
|
||
// Validate performs the validation. | ||
Validate(context.Context, ValidateDataSourceConfigRequest, *ValidateDataSourceConfigResponse) | ||
} | ||
|
||
// DataSourceWithConfigValidators is an interface type that extends DataSource to include declarative validations. | ||
type DataSourceWithConfigValidators interface { | ||
DataSource | ||
|
||
// ConfigValidators returns a list of functions which will all be performed during validation. | ||
bflad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ConfigValidators(context.Context) []DataSourceConfigValidator | ||
} | ||
|
||
// DataSourceWithValidateConfig is an interface type that extends DataSource to include imperative validation. | ||
bflad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
type DataSourceWithValidateConfig interface { | ||
DataSource | ||
|
||
// ValidateConfig performs the validation. | ||
ValidateConfig(context.Context, ValidateDataSourceConfigRequest, *ValidateDataSourceConfigResponse) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package tfsdk | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
// ProviderConfigValidator describes reusable Provider configuration validation functionality. | ||
type ProviderConfigValidator interface { | ||
// Description describes the validation in plain text formatting. | ||
Description(context.Context) string | ||
|
||
// MarkdownDescription describes the validation in Markdown formatting. | ||
MarkdownDescription(context.Context) string | ||
|
||
// Validate performs the validation. | ||
Validate(context.Context, ValidateProviderConfigRequest, *ValidateProviderConfigResponse) | ||
} | ||
|
||
// ProviderWithConfigValidators is an interface type that extends Provider to include declarative validations. | ||
type ProviderWithConfigValidators interface { | ||
Provider | ||
|
||
// ConfigValidators returns a list of functions which will all be performed during validation. | ||
ConfigValidators(context.Context) []ProviderConfigValidator | ||
} | ||
|
||
// ProviderWithValidateConfig is an interface type that extends Provider to include imperative validation. | ||
type ProviderWithValidateConfig interface { | ||
Provider | ||
|
||
// ValidateConfig performs the validation. | ||
ValidateConfig(context.Context, ValidateProviderConfigRequest, *ValidateProviderConfigResponse) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package tfsdk | ||
|
||
// ValidateDataSourceConfigRequest represents a request to validate the | ||
// configuration of a data source. An instance of this request struct is | ||
// supplied as an argument to the DataSource ValidateConfig receiver method | ||
// or automatically passed through to each ConfigValidator. | ||
type ValidateDataSourceConfigRequest struct { | ||
// Config is the configuration the user supplied for the data source. | ||
// | ||
// This configuration may contain unknown values if a user uses | ||
// interpolation or other functionality that would prevent Terraform | ||
// from knowing the value at request time. | ||
Config Config | ||
|
||
// TypeName is the data source type name. | ||
TypeName string | ||
bflad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// ValidateProviderConfigRequest represents a request to validate the | ||
// configuration of a provider. An instance of this request struct is | ||
// supplied as an argument to the Provider ValidateConfig receiver method | ||
// or automatically passed through to each ConfigValidator. | ||
type ValidateProviderConfigRequest struct { | ||
// Config is the configuration the user supplied for the provider. | ||
// | ||
// This configuration may contain unknown values if a user uses | ||
// interpolation or other functionality that would prevent Terraform | ||
// from knowing the value at request time. | ||
Config Config | ||
} | ||
|
||
// ValidateResourceConfigRequest represents a request to validate the | ||
// configuration of a resource. An instance of this request struct is | ||
// supplied as an argument to the Resource ValidateConfig receiver method | ||
// or automatically passed through to each ConfigValidator. | ||
type ValidateResourceConfigRequest struct { | ||
// Config is the configuration the user supplied for the resource. | ||
// | ||
// This configuration may contain unknown values if a user uses | ||
// interpolation or other functionality that would prevent Terraform | ||
// from knowing the value at request time. | ||
Config Config | ||
|
||
// TypeName is the resource type name. | ||
TypeName string | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package tfsdk | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
// ResourceConfigValidator describes reusable Resource configuration validation functionality. | ||
type ResourceConfigValidator interface { | ||
// Description describes the validation in plain text formatting. | ||
Description(context.Context) string | ||
|
||
// MarkdownDescription describes the validation in Markdown formatting. | ||
MarkdownDescription(context.Context) string | ||
|
||
// Validate performs the validation. | ||
Validate(context.Context, ValidateResourceConfigRequest, *ValidateResourceConfigResponse) | ||
} | ||
|
||
// ResourceWithConfigValidators is an interface type that extends Resource to include declarative validations. | ||
type ResourceWithConfigValidators interface { | ||
Resource | ||
|
||
// ConfigValidators returns a list of functions which will all be performed during validation. | ||
ConfigValidators(context.Context) []ResourceConfigValidator | ||
} | ||
|
||
// ResourceWithValidateConfig is an interface type that extends Resource to include imperative validation. | ||
type ResourceWithValidateConfig interface { | ||
Resource | ||
|
||
// ValidateConfig performs the validation. | ||
ValidateConfig(context.Context, ValidateResourceConfigRequest, *ValidateResourceConfigResponse) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package tfsdk | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-go/tfprotov6" | ||
) | ||
|
||
// ValidateDataSourceConfigResponse represents a response to a | ||
// ValidateDataSourceConfigRequest. An instance of this response struct is | ||
// supplied as an argument to the DataSource ValidateConfig receiver method | ||
// or automatically passed through to each ConfigValidator. | ||
type ValidateDataSourceConfigResponse struct { | ||
// Diagnostics report errors or warnings related to validating the data | ||
// source configuration. An empty slice indicates success, with no warnings | ||
// or errors generated. | ||
Diagnostics []*tfprotov6.Diagnostic | ||
} | ||
|
||
// ValidateResourceConfigResponse represents a response to a | ||
// ValidateResourceConfigRequest. An instance of this response struct is | ||
// supplied as an argument to the Resource ValidateConfig receiver method | ||
// or automatically passed through to each ConfigValidator. | ||
type ValidateResourceConfigResponse struct { | ||
// Diagnostics report errors or warnings related to validating the resource | ||
// configuration. An empty slice indicates success, with no warnings or | ||
// errors generated. | ||
Diagnostics []*tfprotov6.Diagnostic | ||
} | ||
|
||
// ValidateProviderConfigResponse represents a response to a | ||
// ValidateProviderConfigRequest. An instance of this response struct is | ||
// supplied as an argument to the Provider ValidateConfig receiver method | ||
// or automatically passed through to each ConfigValidator. | ||
type ValidateProviderConfigResponse struct { | ||
// Diagnostics report errors or warnings related to validating the provider | ||
// configuration. An empty slice indicates success, with no warnings or | ||
// errors generated. | ||
Diagnostics []*tfprotov6.Diagnostic | ||
} |
Uh oh!
There was an error while loading. Please reload this page.