Documentation ¶
Overview ¶
Package validator contains common schema validator interfaces and implementations. These validators are used by concept specific packages such as datasource/schema, provider/schema, and resource/schema.
Each attr.Type has a corresponding {TYPE}Validator interface which implements concretely typed Validate{TYPE} methods, such as StringValidator and ValidateString. Custom attr.Type can also consider implementing native type validation via the attr/xattr.TypeWithValidate interface instead of schema validators.
The framework has to choose between validator developers handling a concrete framework value type, such as types.Bool, or the framework interface for custom value basetypes. such as basetypes.BoolValuable.
In the framework type model, the developer can immediately use the value. If the value was associated with a custom type and using the custom value type is desired, the developer must use the type's ValueFrom{TYPE} method.
In the custom type model, the developer must always convert to a concreate type before using the value unless checking for null or unknown. Since any custom type may be passed due to the schema, it is possible, if not likely, that unknown concrete types will be passed to the validator.
The framework chooses to pass the framework value type. This prevents the potential for unexpected runtime panics and simplifies development for easier use cases where the framework type is sufficient. More advanced developers can choose to implement native type validation for custom types or call the type's ValueFrom{TYPE} method to get the desired desired custom type in a validator.
Validators that are not type dependent need to implement all interfaces, but can use shared logic to reduce implementation code.
Index ¶
- type Bool
- type BoolRequest
- type BoolResponse
- type Describer
- type Float64
- type Float64Request
- type Float64Response
- type Int64
- type Int64Request
- type Int64Response
- type List
- type ListRequest
- type ListResponse
- type Map
- type MapRequest
- type MapResponse
- type Number
- type NumberRequest
- type NumberResponse
- type Object
- type ObjectRequest
- type ObjectResponse
- type Set
- type SetRequest
- type SetResponse
- type String
- type StringRequest
- type StringResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bool ¶
type Bool interface { Describer // ValidateBool should perform the validation. ValidateBool(context.Context, BoolRequest, *BoolResponse) }
Bool is a schema validator for types.Bool attributes.
type BoolRequest ¶
type BoolRequest struct { // Path contains the path of the attribute for validation. Use this path // for any response diagnostics. Path path.Path // PathExpression contains the expression matching the exact path // of the attribute for validation. PathExpression path.Expression // Config contains the entire configuration of the data source, provider, or resource. Config tfsdk.Config // ConfigValue contains the value of the attribute for validation from the configuration. ConfigValue types.Bool }
BoolRequest is a request for types.Bool schema validation.
type BoolResponse ¶
type BoolResponse 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 diag.Diagnostics }
BoolResponse is a response to a BoolRequest.
type Describer ¶
type Describer interface { // Description should describe the validation in plain text formatting. // This information is used by provider logging and provider tooling such // as documentation generation. // // The description should: // - Begin with a lowercase or other character suitable for the middle of // a sentence. // - End without punctuation. // - Use actionable language, such as "must" or "cannot". // - Avoid newlines. Prefer separate validators instead. // // For example, "size must be less than 50 elements". Description(context.Context) string // MarkdownDescription should describe the validation in Markdown // formatting. This information is used by provider logging and provider // tooling such as documentation generation. // // The description should: // - Begin with a lowercase or other character suitable for the middle of // a sentence. // - End without punctuation. // - Use actionable language, such as "must" or "cannot". // - Avoid newlines. Prefer separate validators instead. // // For example, "value must be `one` or `two`". MarkdownDescription(context.Context) string }
Describer is the common documentation interface for extensible schema validation functionality.
type Float64 ¶
type Float64 interface { Describer // ValidateFloat64 should perform the validation. ValidateFloat64(context.Context, Float64Request, *Float64Response) }
Float64 is a schema validator for types.Float64 attributes.
type Float64Request ¶
type Float64Request struct { // Path contains the path of the attribute for validation. Use this path // for any response diagnostics. Path path.Path // PathExpression contains the expression matching the exact path // of the attribute for validation. PathExpression path.Expression // Config contains the entire configuration of the data source, provider, or resource. Config tfsdk.Config // ConfigValue contains the value of the attribute for validation from the configuration. ConfigValue types.Float64 }
Float64Request is a request for types.Float64 schema validation.
type Float64Response ¶
type Float64Response 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 diag.Diagnostics }
Float64Response is a response to a Float64Request.
type Int64 ¶
type Int64 interface { Describer // ValidateInt64 should perform the validation. ValidateInt64(context.Context, Int64Request, *Int64Response) }
Int64 is a schema validator for types.Int64 attributes.
type Int64Request ¶
type Int64Request struct { // Path contains the path of the attribute for validation. Use this path // for any response diagnostics. Path path.Path // PathExpression contains the expression matching the exact path // of the attribute for validation. PathExpression path.Expression // Config contains the entire configuration of the data source, provider, or resource. Config tfsdk.Config // ConfigValue contains the value of the attribute for validation from the configuration. ConfigValue types.Int64 }
Int64Request is a request for types.Int64 schema validation.
type Int64Response ¶
type Int64Response 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 diag.Diagnostics }
Int64Response is a response to a Int64Request.
type List ¶
type List interface { Describer // ValidateList should perform the validation. ValidateList(context.Context, ListRequest, *ListResponse) }
List is a schema validator for types.List attributes.
type ListRequest ¶
type ListRequest struct { // Path contains the path of the attribute for validation. Use this path // for any response diagnostics. Path path.Path // PathExpression contains the expression matching the exact path // of the attribute for validation. PathExpression path.Expression // Config contains the entire configuration of the data source, provider, or resource. Config tfsdk.Config // ConfigValue contains the value of the attribute for validation from the configuration. ConfigValue types.List }
ListRequest is a request for types.List schema validation.
type ListResponse ¶
type ListResponse 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 diag.Diagnostics }
ListResponse is a response to a ListRequest.
type Map ¶
type Map interface { Describer // ValidateMap should perform the validation. ValidateMap(context.Context, MapRequest, *MapResponse) }
Map is a schema validator for types.Map attributes.
type MapRequest ¶
type MapRequest struct { // Path contains the path of the attribute for validation. Use this path // for any response diagnostics. Path path.Path // PathExpression contains the expression matching the exact path // of the attribute for validation. PathExpression path.Expression // Config contains the entire configuration of the data source, provider, or resource. Config tfsdk.Config // ConfigValue contains the value of the attribute for validation from the configuration. ConfigValue types.Map }
MapRequest is a request for types.Map schema validation.
type MapResponse ¶
type MapResponse 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 diag.Diagnostics }
MapResponse is a response to a MapRequest.
type Number ¶
type Number interface { Describer // ValidateNumber should perform the validation. ValidateNumber(context.Context, NumberRequest, *NumberResponse) }
Number is a schema validator for types.Number attributes.
type NumberRequest ¶
type NumberRequest struct { // Path contains the path of the attribute for validation. Use this path // for any response diagnostics. Path path.Path // PathExpression contains the expression matching the exact path // of the attribute for validation. PathExpression path.Expression // Config contains the entire configuration of the data source, provider, or resource. Config tfsdk.Config // ConfigValue contains the value of the attribute for validation from the configuration. ConfigValue types.Number }
NumberRequest is a request for types.Number schema validation.
type NumberResponse ¶
type NumberResponse 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 diag.Diagnostics }
NumberResponse is a response to a NumberRequest.
type Object ¶
type Object interface { Describer // ValidateObject should perform the validation. ValidateObject(context.Context, ObjectRequest, *ObjectResponse) }
Object is a schema validator for types.Object attributes.
type ObjectRequest ¶
type ObjectRequest struct { // Path contains the path of the attribute for validation. Use this path // for any response diagnostics. Path path.Path // PathExpression contains the expression matching the exact path // of the attribute for validation. PathExpression path.Expression // Config contains the entire configuration of the data source, provider, or resource. Config tfsdk.Config // ConfigValue contains the value of the attribute for validation from the configuration. ConfigValue types.Object }
ObjectRequest is a request for types.Object schema validation.
type ObjectResponse ¶
type ObjectResponse 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 diag.Diagnostics }
ObjectResponse is a response to a ObjectRequest.
type Set ¶
type Set interface { Describer // ValidateSet should perform the validation. ValidateSet(context.Context, SetRequest, *SetResponse) }
Set is a schema validator for types.Set attributes.
type SetRequest ¶
type SetRequest struct { // Path contains the path of the attribute for validation. Use this path // for any response diagnostics. Path path.Path // PathExpression contains the expression matching the exact path // of the attribute for validation. PathExpression path.Expression // Config contains the entire configuration of the data source, provider, or resource. Config tfsdk.Config // ConfigValue contains the value of the attribute for validation from the configuration. ConfigValue types.Set }
SetRequest is a request for types.Set schema validation.
type SetResponse ¶
type SetResponse 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 diag.Diagnostics }
SetResponse is a response to a SetRequest.
type String ¶
type String interface { Describer // ValidateString should perform the validation. ValidateString(context.Context, StringRequest, *StringResponse) }
String is a schema validator for types.String attributes.
type StringRequest ¶
type StringRequest struct { // Path contains the path of the attribute for validation. Use this path // for any response diagnostics. Path path.Path // PathExpression contains the expression matching the exact path // of the attribute for validation. PathExpression path.Expression // Config contains the entire configuration of the data source, provider, or resource. Config tfsdk.Config // ConfigValue contains the value of the attribute for validation from the configuration. ConfigValue types.String }
StringRequest is a request for types.String schema validation.
type StringResponse ¶
type StringResponse 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 diag.Diagnostics }
StringResponse is a response to a StringRequest.