Skip to content

ListValidator

List validator are used to validate the plan of a list attribute. It will be used into the Validators field of the schema.ListAttribute struct.

How to use it

import (
    flistvalidator "github.com/FrangipaneTeam/terraform-plugin-framework-validators/listvalidator"
)

List of Validators

Every string validators are available for maps thanks to a generic validator provided by Hashicorp. See the section below for more details.

  • RequireIfAttributeIsOneOf - This validator is used to require the attribute if another attribute is one of the given values.
  • RequireIfAttributeIsSet - This validator is used to require the attribute if another attribute is set.
  • NullIfAttributeIsOneOf - This validator is used to verify the attribute value is null if another attribute is one of the given values.
  • NullIfAttributeIsSet - This validator is used to verify the attribute value is null if another attribute is set.

Special

  • Not - This validator is used to negate the result of another validator.

Generic

String

Hashicorp provides a generic validator for strings. It uses the validators already defined in string to validate a list of strings. It is available in the hashicorp stringvalidator package.

Example of usage:

// Used within a Schema method of a DataSource, Provider, or Resource
_ = schema.Schema{
    Attributes: map[string]schema.Attribute{
        "example_attr": schema.ListAttribute{
            ElementType: types.StringType,
            Required:    true,
            Validators: []validator.List{
                // Validate this List must contain string values which are at least 3 characters.
                listvalidator.ValueStringsAre(fstringvalidator.IsUUID()),
            },
        },
    },
}