Skip to content
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

Add wrapper functions for validation helper without Diagnostics #534

Closed
pavel-github opened this issue Aug 12, 2020 · 4 comments
Closed
Labels
enhancement New feature or request

Comments

@pavel-github
Copy link

SDK version

github.com/hashicorp/terraform-plugin-sdk/v2
v2.0.0

Use-cases

The field ValidateFunc of Schema type is deprecated since v2. Now we should use ValidateDiagFunc, but all validation helper (except map helper) use schema.SchemaValidateFunc and not schema.SchemaValidateDiagFunc.

Attempted Solutions

What we tried to do in our plugin was create function that wraps existing validation helpers and returns diag.Diagnostics instead of errors.

Proposal

To help with migration from v1 to v2 we could create wrapper functions for every validation helper that return schema.SchemaValidateDiagFunc instead of schema.SchemaValidateFunc.

References

@pavel-github pavel-github added the enhancement New feature or request label Aug 12, 2020
ozerovandrei added a commit to ozerovandrei/terraform-provider-selectel that referenced this issue Aug 27, 2020
Use the next major version of SDK.

Remove usage of all deprecated functions.

Only leave ValidateFunc for now since there are currently no wrappers
for the existing validation helpers.
See: hashicorp/terraform-plugin-sdk#534.

Refactor "theme" in resource_selectel_vpc_project_v2 to use map of
strings since map of resources is not possible anymore.
See: hashicorp/terraform-plugin-sdk#338

Add internal mutexkv and hashcode implementations from v1 SDK.
See: hashicorp/terraform-plugin-sdk#438
ozerovandrei added a commit to ozerovandrei/terraform-provider-selectel that referenced this issue Aug 27, 2020
Use the next major version of SDK.

Remove usage of all deprecated functions.

Only leave ValidateFunc for now since there are currently no wrappers
for the existing validation helpers.
See: hashicorp/terraform-plugin-sdk#534.

Refactor "theme" in resource_selectel_vpc_project_v2 to use map of
strings since map of resources is not possible anymore.
See: hashicorp/terraform-plugin-sdk#338

Add internal mutexkv and hashcode implementations from v1 SDK.
See: hashicorp/terraform-plugin-sdk#438
ozerovandrei added a commit to selectel/terraform-provider-selectel that referenced this issue Aug 28, 2020
* Upgrade Terraform SDK to v2.0.1

Use the next major version of SDK.

Remove usage of all deprecated functions.

Only leave ValidateFunc for now since there are currently no wrappers
for the existing validation helpers.
See: hashicorp/terraform-plugin-sdk#534.

Refactor "theme" in resource_selectel_vpc_project_v2 to use map of
strings since map of resources is not possible anymore.
See: hashicorp/terraform-plugin-sdk#338

Add internal mutexkv and hashcode implementations from v1 SDK.
See: hashicorp/terraform-plugin-sdk#438

* Add TestFlattenVPCProjectV2Theme unit test

Add test for flattenVPCProjectV2Theme function.
@birchb1024
Copy link

Maybe something like this:

				ValidateDiagFunc : validateV1(validation.IsURLWithHTTPorHTTPS),

Would this sort of curry work?

func validateV1(fn schema.SchemaValidateFunc) (schema.SchemaValidateDiagFunc) {
	return func(v interface{}, path cty.Path) diag.Diagnostics {
		var diags diag.Diagnostics

		warnings, errors := fn(v, fmt.Sprintf("%#v", path))
		for _, w := range warnings {
			diags = append(diags, diag.Diagnostic{
				Severity:      diag.Warning,
				Summary:       w,
				Detail:        w,
				AttributePath: path,
			})
		}
		for _, err := range errors {
			diags = append(diags, diag.Diagnostic{
				Severity:      diag.Warning,
				Summary:       err.Error(),
				Detail:        err.Error(),
				AttributePath: path,
			})
		}
		return diags
	}
}

@risicle
Copy link

risicle commented Dec 15, 2020

Similarly, the All() and Any() functions only take schema.SchemaValidateFunc, which is pretty annoying.

@paddycarver
Copy link
Contributor

This was released with version 2.4.0 of the SDK.

@ghost
Copy link

ghost commented Feb 6, 2021

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked as resolved and limited conversation to collaborators Feb 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants