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

Description

@mavogel

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

Links

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions