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 ¶
- func AtLeastOneNonEmptyAttribute(attributeNames ...string) validator.Object
- func BoolRequiresBool(attrValue types.Bool, requiredAttrValue types.Bool, attrName string, ...) diag.Diagnostics
- func ListObjectUniqueString(attributeName string) validator.List
- func SortField(validFields []string) validator.String
- func StringIsEmailAddress() validator.String
- func StringNotWhitespace() validator.String
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AtLeastOneNonEmptyAttribute ¶ added in v0.0.61
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 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 ListObjectUniqueString ¶
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 SortField ¶ added in v0.0.50
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 ¶
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 ¶
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.