This repository was archived by the owner on Feb 21, 2023. It is now read-only.
This repository was archived by the owner on Feb 21, 2023. It is now read-only.
feat: add example of usage of ValidateDiagFunc #47
Open
Description
Details
An example of
- how to use this function instead of the old
ValidateFunc
- and how to test it
would be helpful.
Currently, I cannot get it running:
"host_path": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateDiagFunc: validateDockerContainerPath,
},
and the implementation:
func validateDockerContainerPath() schema.SchemaValidateDiagFunc {
return func(v interface{}, path cty.Path) diag.Diagnostics {
value := v.(string)
var diags diag.Diagnostics
if !regexp.MustCompile(`^[a-zA-Z]:\\|^/`).MatchString(value) {
diags = append(diags, diag.Errorf("%q must be an absolute path", value)...)
}
return diags
}
}
I get the error
cannot use validateDockerContainerPath (value of type func() schema.SchemaValidateDiagFunc) as schema.SchemaValidateDiagFunc value in struct literal
Versions
- terraform:
v0.14.3
- github.com/hashicorp/terraform-plugin-sdk/v2
v2.4.0