@@ -21,10 +21,11 @@ changes as possible but, as always, community help is appreciated!
2121| ----------------------------| -----------------|
2222| v0.7.0-v0.9.0 | v1 |
2323| v0.10.x-v0.15.x | v2 |
24+ | v1.x | v3 |
2425
2526# Installation
2627``` shell
27- go get -u github.com/dcarbone/terraform-plugin-framework-utils/v2 @latest
28+ go get -u github.com/dcarbone/terraform-plugin-framework-utils/v3 @latest
2829```
2930
3031# Type Conversion
@@ -37,14 +38,14 @@ and from Terraform and Go easy and obvious.
3738You can see the complete list of available conversions here:
3839[ terraform-plugin-framework-utils/conv] ( https://github.com/dcarbone/terraform-plugin-framework-utils/blob/main/conv )
3940
40- # Attribute Validation
41+ # Generic Validation
4142
42- The Terraform Plugin Framework has a great [ validation] ( https://www.terraform.io/plugin/framework/validation ) interface
43- that makes it easy to create custom validation rules for the various schemas you define in your provider.
43+ The Terraform Plugin Framework has a great set of per-value type validator interfaces that you may implement as needed:
44+ [ validators] ( https://www.terraform.io/plugin/framework/validation ) . This does not always fit the need, however,
45+ as some validations need not be aware of type, or may benefit from being applicable to multiple types.
4446
45- Being in beta, the HashiCorp team has yet to provide a built-in set of providers. I have created a few that I have
46- found useful when creating my own providers, and provided a small wrapper to make creating new providers as
47- simple as [ defining a function] ( validation/validators.go#25 ) .
47+ To facilitate this, I have created a few that I have found useful when creating my own providers, and defined a
48+ small wrapper to make creating new validators as simple as [ defining a function] ( validation/validators.go#19 ) .
4849
4950## Provided Validators
5051
@@ -54,7 +55,7 @@ Fails validation if the attribute is null or unknown
5455
5556``` go
5657{
57- Validators : []tfsdk. AttributeValidator {
58+ Validators : []validator.{Type} {
5859 validation.Required ()
5960 },
6061}
@@ -67,7 +68,7 @@ will attempt to convert the attribute to a string first.
6768
6869``` go
6970{
70- Validators : []tfsdk. AttributeValidator {
71+ Validators : []validator.{Type} {
7172 validation.RegexpMatch (" {{ your regex here }}" )
7273 },
7374}
@@ -80,7 +81,7 @@ will attempt to convert the attribute to a string first.
8081
8182``` go
8283{
83- Validators : []tfsdk. AttributeValidator {
84+ Validators : []validator.{Type} {
8485 validation.RegexpNotMatch (" {{ your regex here }}" )
8586 },
8687}
@@ -92,7 +93,7 @@ Fails validation if the attribute's value's length is not within the specified b
9293
9394``` go
9495{
95- Validators : []tfsdk. AttributeValidator {
96+ Validators : []validator.{Type} {
9697 // lower limit
9798 validation.Length (5 , -1 ),
9899
@@ -114,7 +115,7 @@ your own [ComparisonFunc](validation/comparison.go#44) using [SetComparisonFunc]
114115
115116``` go
116117{
117- Validators : []tfsdk. AttributeValidator {
118+ Validators : []validator.{Type} {
118119 // equal
119120 validation.Compare (validation.Equal , 5 ),
120121 // string comparisons are case sensitive by default
@@ -174,7 +175,7 @@ Fails validation if the attribute's value is not parseable by `url.Parse`
174175
175176``` go
176177{
177- Validators : []tfsdk. AttributeValidator {
178+ Validators : []validator.{Type} {
178179 validation.IsUrl ()
179180 }
180181}
@@ -186,7 +187,7 @@ Fails validation if the attribute's value is not parseable by `time.ParseDuratio
186187
187188``` go
188189{
189- Validators : []tfsdk. AttributeValidator {
190+ Validators : []validator.{Type} {
190191 validation.IsDurationString ()
191192 }
192193}
@@ -198,7 +199,7 @@ Fails validation if the environment variable name defined by the attribute's val
198199
199200``` go
200201{
201- Validators : []tfsdk. AttributeValidator {
202+ Validators : []validator.{Type} {
202203 validation.EnvVarValued ()
203204 }
204205}
@@ -210,7 +211,7 @@ Fails validation if the file at the path defined in the attribute's value is not
210211
211212``` go
212213{
213- Validators : []tfsdk. AttributeValidator {
214+ Validators : []validator.{Type} {
214215 validation.FileIsReadable ()
215216 }
216217}
@@ -222,7 +223,7 @@ Fails validation if the attribute is valued and the configured sibling attribute
222223
223224``` go
224225{
225- Validators : []tfsdk. AttributeValidator {
226+ Validators : []validator.{Type} {
226227 validation.MutuallyExclusiveSibling (" {{ sibling field name }}" )
227228 }
228229}
@@ -241,7 +242,7 @@ provider "whatever" {
241242``` go
242243// Example validators list defined on the `address` attribute's schema
243244{
244- Validators : []tfsdk. AttributeValidator {
245+ Validators : []validator.{Type} {
245246 validation.MutuallyExclusiveSibling (" address_env" )
246247 }
247248}
@@ -257,7 +258,7 @@ Requires that two sibling attributes either both be valued or not valued.
257258
258259``` go
259260{
260- Validators : []tfsdk. AttributeValidator {
261+ Validators : []validator.{Type} {
261262 validation.MutuallyInclusiveSibling (" {{ sibling field name }}" )
262263 }
263264}
@@ -276,7 +277,7 @@ provider "whatever" {
276277``` go
277278// Example validators list defined on the `ssh_key_password` attribute's schema
278279{
279- Validators : []tfsdk. AttributeValidator {
280+ Validators : []validator.{Type} {
280281 validation.MutuallyInclusiveSibling (" ssh_key" )
281282 }
282283}
0 commit comments