schemautil

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package schemautil provides utilities for working with Terraform resource schemas.

Package schemautil provides utilities for working with Terraform resource schemas.

Note that this package uses legacy logging because the provider context is not available

Index

Constants

View Source
const (
	NormalizedFieldNameRegex string = `[^a-z0-9_]+`
)

Variables

This section is empty.

Functions

func CronExpression

CronExpression returns a SchemaValidateDiagFunc that validates a cron expression.

func MustNormalizeFieldName

func MustNormalizeFieldName(fieldName string) string

MustNormalizeFieldName is the same as NormalizeFieldName, but will log an error (legacy logging) instead of returning it.

func MustNormalizeYamlString

func MustNormalizeYamlString(yamlString interface{}) string

MustNormalizeYamlString is the same as NormalizeYamlString, but will log an error (legacy logging) instead of returning it.

func NormalizeFieldName

func NormalizeFieldName(fieldName string) (string, error)

NormalizeFieldName normalizes a field name to be lowercase and contain only alphanumeric characters and dashes.

func NormalizeYamlString

func NormalizeYamlString(yamlString interface{}) (string, error)

NormalizeYAMLString normalizes a YAML string to a standardized order, format and indentation.

func StringIsValidRegExp

func StringIsValidRegExp(opts ...ValidationOptionSetter) schema.SchemaValidateDiagFunc

StringIsValidRegExp returns a SchemaValidateDiagFunc which validates that a string is a valid regular expression.

This function has similar functionality to StringIsValidRegExp from the terraform plugin SDK. https://github.com/hashicorp/terraform-plugin-sdk/blob/695f0c7b92e26444786b8963e00c665f1b4ef400/helper/validation/strings.go#L225 It has been modified to use the library https://github.com/dlclark/regexp2 instead of the standard regex golang package in order to support complex regular expressions including perl regex syntax.

It has also been modified to conform to the SchemaValidateDiagFunc type instead of the deprecated SchemaValidateFunc type.

func StringIsValidYaml

func StringIsValidYaml(opts ...ValidationOptionSetter) schema.SchemaValidateDiagFunc

StringIsValidYaml returns a SchemaValidateDiagFunc which validates that a string is valid YAML.

func StringMatchesRegExp

func StringMatchesRegExp(regex string, opts ...ValidationOptionSetter) schema.SchemaValidateDiagFunc

StringMatchesRegExp returns a SchemaValidateDiagFunc which validates that a string matches a regular expression.

func SuppressEquivalentYamlDiffs

func SuppressEquivalentYamlDiffs() schema.SchemaDiffSuppressFunc

SuppressEquivalentYamlDiffs returns SchemaDiffSuppressFunc that suppresses diffs between equivalent YAML strings.

Types

type CronValidationOptions

type CronValidationOptions struct {
	// contains filtered or unexported fields
}

CronValidationOptions contains options for validating cron expressions.

type StringValidationOptions

type StringValidationOptions struct {
	// contains filtered or unexported fields
}

StringValidationOptions contains options for validating strings.

type ValidationOptionSetter

type ValidationOptionSetter func(*ValidationOptions)

func WithCronParser

func WithCronParser(parser cron.Parser) ValidationOptionSetter

WithParser overrides the cron parser used to validate cron expressions.

func WithDetailFormat

func WithDetailFormat(detailFormat string) ValidationOptionSetter

WithDetailFormat overrides the detail format string of the validation error.

This string is passed to fmt.Sprintf. The verbs used in the format string depend on the implementation of the validation function.

func WithRegexOptions

func WithRegexOptions(options regexp2.RegexOptions) ValidationOptionSetter

WithRegexOptions overrides the regex options used to validate regular expressions.

func WithSeverity

func WithSeverity(severity diag.Severity) ValidationOptionSetter

WithSeverity overrides the severity of the validation error.

func WithSummary

func WithSummary(summary string) ValidationOptionSetter

WithSummary overrides the summary of the validation error.

type ValidationOptions

type ValidationOptions struct {
	// contains filtered or unexported fields
}

func NewValidationOptions

func NewValidationOptions() *ValidationOptions

NewValidationOptions returns a new ValidationOptions struct with default values.

Jump to

Keyboard shortcuts

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