Help us shape the future of Go! Take the 2026 Go Developer Survey

validators

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2026 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package validators provides reusable Terraform schema validators and utilities for the CrowdStrike Terraform Provider.

This package contains custom validators that extend the Terraform Plugin Framework's built-in validation capabilities with common validation patterns used throughout the provider.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AtLeastOneNonEmptyAttribute added in v0.0.61

func AtLeastOneNonEmptyAttribute(attributeNames ...string) validator.Object

AtLeastOneNonEmptyAttribute returns a validator that ensures at least one of the specified attributes in an object is non-empty (not null/unknown and containing actual values).

This is useful for validating nested objects where at least one attribute must be provided with actual values.

Example usage:

Validators: []validator.Object{
    validators.AtLeastOneNonEmptyAttribute("ids", "names", "types"),
}

func AttributeRequiresBool added in v0.0.85

func AttributeRequiresBool(
	attrValue attr.Value,
	requiredAttrValue types.Bool,
	attrName string,
	requiredAttrName string,
) diag.Diagnostics

AttributeRequiresBool validates that when an attribute of any type is configured, a controlling boolean attribute must be enabled.

This is used in ValidateConfig methods for cross-attribute validation. Returns empty diagnostics if validation passes, or diagnostics with an error if the attribute is configured but the required boolean attribute is not enabled.

Null (unconfigured) and unknown (known after apply) values are skipped.

Example: Validate that "file_size_threshold" requires "file_scanning" to be enabled:

resp.Diagnostics.Append(
    validators.AttributeRequiresBool(
        config.FileSizeThreshold,
        config.FileScanning,
        "file_size_threshold",
        "file_scanning",
    )...)

func BoolRequiresBool added in v0.0.62

func BoolRequiresBool(
	attrValue types.Bool,
	requiredAttrValue types.Bool,
	attrName string,
	requiredAttrName string,
) diag.Diagnostics

BoolRequiresBool validates that when one boolean attribute is enabled, another boolean attribute must also be enabled.

This is used in ValidateConfig methods for cross-attribute validation. Returns empty diagnostics if validation passes, or diagnostics with an error if the first attribute is enabled but the required attribute is not.

Null (unconfigured) and unknown (known after apply) values are skipped.

Example: Validate that "falcon_scripts" requires "custom_scripts" to be enabled:

resp.Diagnostics.Append(
    validators.BoolRequiresBool(
        config.FalconScripts,
        config.CustomScripts,
        "falcon_scripts",
        "custom_scripts",
    )...)

func BoolRequiresStringValue added in v0.0.85

func BoolRequiresStringValue(
	attrValue types.Bool,
	controllingValue types.String,
	attrName string,
	controllingName string,
	requiredValue string,
) diag.Diagnostics

BoolRequiresStringValue validates that when a boolean attribute is enabled, a controlling string attribute must equal a specific value.

This is used in ValidateConfig methods for cross-attribute validation. Returns empty diagnostics if validation passes, or diagnostics with an error if the attribute is enabled but the controlling attribute does not equal the required value.

Null (unconfigured) and unknown (known after apply) values are skipped, as is a boolean that is disabled: switching a feature off never constrains what enables it.

Example: Validate that "block_everything" requires "mode" to be "strict":

resp.Diagnostics.Append(
    validators.BoolRequiresStringValue(
        config.BlockEverything,
        config.Mode,
        "block_everything",
        "mode",
        "strict",
    )...)

func CID added in v0.0.84

func CID() validator.String

CID validates a CrowdStrike CID.

func ListObjectUniqueString

func ListObjectUniqueString(attributeName string) validator.List

ListObjectUniqueString returns a validator that ensures each object in a list has a unique value for the specified string attribute.

This validator is designed for lists of objects where you need to ensure that a particular string field is unique across all objects. For example, when validating a list of image objects where each object has a "registry" string attribute, this validator ensures that no two objects have the same registry value.

attributeName: The name of the string attribute to check for uniqueness across all objects in the list.

func SetJoinedLengthAtMost added in v0.0.85

func SetJoinedLengthAtMost(separator string, maxLength int) validator.Set

SetJoinedLengthAtMost validates that the set's elements, joined with separator, are at most maxLength characters.

For an attribute the provider serializes as a single delimited string, the API's limit applies to the joined value rather than to any one element. A per-element length check is the wrong bound: it accepts any number of short elements whose join overruns the limit, which is the case the API actually rejects.

Null and unknown sets are skipped, as are sets containing an unknown element, because the join cannot be computed until every element is known.

func SortField added in v0.0.50

func SortField(validFields []string) validator.String

SortField returns a validator that ensures a string is a valid sort field from the provided list with either .asc or .desc suffix.

The validator checks that: 1. The string ends with either ".asc" or ".desc" 2. The field name (before the suffix) is in the list of valid fields

Null (unconfigured) and unknown (known after apply) values are skipped.

func StringIsEmailAddress

func StringIsEmailAddress() validator.String

StringIsEmailAddress returns a validator that ensures a string attribute is a valid email address format.

The validator uses a regex pattern to check that the string conforms to a basic email address format. Null (unconfigured) and unknown (known after apply) values are skipped.

Valid values: "user@example.com", "test.user+tag@domain.co.uk" Invalid values: "notanemail", "missing@domain", "@example.com", "user@".

func StringNotWhitespace

func StringNotWhitespace() validator.String

StringNotWhitespace returns a validator that ensures a string attribute is not empty or composed only of whitespace characters.

The validator uses a regex pattern (\S) to check that the string contains at least one non-whitespace character. Null (unconfigured) and unknown (known after apply) values are skipped.

Valid values: "test", "test value", "a" Invalid values: "", " ", " ", "\t", "\n", " \t\n ".

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL