validation

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrorReasonCodeMissingType is provided when the reason
	// for a blueprint spec load error is due to the version property
	// not being provided for a blueprint.
	ErrorReasonCodeMissingVersion errors.ErrorReasonCode = "missing_version"
	// ErrorReasonCodeInvalidVersion is provided when the reason
	// for a blueprint spec load error is due to an invalid version
	// of the spec being provided.
	ErrorReasonCodeInvalidVersion errors.ErrorReasonCode = "invalid_version"
	// ErrorReasonCodeInvalidResource is provided when the reason
	// for a blueprint spec load error is due to one or more resources
	// being invalid.
	ErrorReasonCodeInvalidResource errors.ErrorReasonCode = "invalid_resource"
	// ErrorReasonCodeMissingResourcesOrIncludes is provided when the reason
	// for a blueprint spec load error is due no resources or includes
	// being defined in the blueprint.
	// An empty map or omitted property will result in this error.
	ErrorReasonCodeMissingResourcesOrIncludes errors.ErrorReasonCode = "missing_resources"
	// ErrorReasonCodeInvalidVariable is provided when the reason
	// for a blueprint spec load error is due to one or more variables
	// being invalid.
	// This could be due to a mismatch between the type and the value,
	// a missing required variable (one without a default value),
	// an invalid default value, invalid allowed values or an incorrect variable type.
	ErrorReasonCodeInvalidVariable errors.ErrorReasonCode = "invalid_variable"
	// ErrorReasonCodeInvalidValue is provided when the reason
	// for a blueprint spec load error is due to an invalid value
	// being provided.
	ErrorReasonCodeInvalidValue errors.ErrorReasonCode = "invalid_value"
	// ErrorReasonCodeInvalidValueType is provided
	// when the reason for a blueprint spec load error is due
	// to an invalid value type.
	ErrorReasonCodeInvalidValueType errors.ErrorReasonCode = "invalid_value_type"
	// ErrorReasonCodeInvalidExport is provided when the reason
	// for a blueprint spec load error is due to one or more exports
	// being invalid.
	ErrorReasonCodeInvalidExport errors.ErrorReasonCode = "invalid_export"
	// ErrorReasonCodeInvalidReference is provided when the reason
	// for a blueprint spec load error is due to one or more references
	// being invalid.
	ErrorReasonCodeInvalidReference errors.ErrorReasonCode = "invalid_reference"
	// ErrorReasonCodeInvalidSubstitution is provided when the reason
	// for a blueprint spec load error is due to one or more substitutions
	// being invalid.
	ErrorReasonCodeInvalidSubstitution errors.ErrorReasonCode = "invalid_substitution"
	// ErrorReasonCodeInvalidInclude is provided when the reason
	// for a blueprint spec load error is due to one or more includes
	// being invalid.
	ErrorReasonCodeInvalidInclude errors.ErrorReasonCode = "invalid_include"
	// ErrorReasonCodeInvalidResource is provided when the reason
	// for a blueprint spec load error is due to one or more data sources
	// being invalid.
	ErrorReasonCodeInvalidDataSource errors.ErrorReasonCode = "invalid_data_source"
	// ErrorReasonCodeInvalidDataSourceFilterOperator is provided
	// when the reason for a blueprint spec load error is due
	// to an invalid data source filter operator being provided.
	ErrorReasonCodeInvalidDataSourceFilterOperator errors.ErrorReasonCode = "invalid_data_source_filter_operator"
	// ErrorReasonCodeUnsupportedDataSourceFilterOperator is provided
	// when the reason for a blueprint spec load error is due
	// to an unsupported data source filter operator being provided.
	ErrorReasonCodeUnsupportedDataSourceFilterOperator errors.ErrorReasonCode = "unsupported_data_source_filter_operator"
	// ErrorReasonCodeInvalidDataSourceFieldType is provided
	// when the reason for a blueprint spec load error is due
	// to an invalid data source field type.
	ErrorReasonCodeInvalidDataSourceFieldType errors.ErrorReasonCode = "invalid_data_source_field_type"
	// ErrorReasonCodeInvalidDataSourceFilterConflict is provided
	// when the reason for a blueprint spec load error is due
	// to a conflict between two filter fields in a data source,
	// where both fields can not be used to filter the same data source.
	ErrorReasonCodeDataSourceFilterConflict errors.ErrorReasonCode = "data_source_filter_conflict"
	// ErrorReasonCodeInvalidMapKey is provided when the reason
	// for a blueprint spec load error is due to an invalid map key.
	ErrorReasonCodeInvalidMapKey errors.ErrorReasonCode = "invalid_map_key"
	// ErrorReasonCodeMultipleValidationErrors is provided when the reason
	// for a blueprint spec load error is due to multiple validation errors.
	ErrorReasonCodeMultipleValidationErrors errors.ErrorReasonCode = "multiple_validation_errors"
	// ErrorReasonCodeReferenceCycle is provided when the reason
	// for a blueprint spec load error is due to a reference cycle being detected.
	// This error code is used to collect and surface reference cycle errors
	// for pure substitution reference cycles and link <-> substitution reference cycles.
	ErrorReasonCodeReferenceCycle errors.ErrorReasonCode = "reference_cycle"
	// ErrorReasonCodeInvalidMappingNode is provided when the reason
	// for a blueprint spec load error is due to an invalid mapping node.
	ErrorReasonCodeInvalidMappingNode errors.ErrorReasonCode = "invalid_mapping_node"
	// ErrorReasonCodeInvalidResourceDependency is provided when the reason
	// for a blueprint spec load error is due to a resource dependency in the "dependsOn"
	// property not being a valid resource.
	ErrorReasonCodeMissingResourceDependency errors.ErrorReasonCode = "missing_resource_dependency"
	// ErrorReasonCodeComputedFieldInBlueprint is provided when the reason
	// for a blueprint spec load error is due to a computed field being used in a blueprint.
	// Computed fields are not allowed to be defined in blueprints,
	// they are computed by providers when a resource has been created.
	ErrorReasonCodeComputedFieldInBlueprint errors.ErrorReasonCode = "computed_field_in_blueprint"
	// ErrorReasonCodeEachResourceDependency is provided when the reason
	// for a blueprint spec load error is due to the "each" property of a resource
	// having a dependency on another resource.
	ErrorReasonCodeEachResourceDependency errors.ErrorReasonCode = "each_resource_dependency"
	// ErrorReasonCodeEachChildDependency is provided when the reason
	// for a blueprint spec load error is due to the "each" property of a resource
	// having a dependency on a child blueprint.
	ErrorReasonCodeEachChildDependency errors.ErrorReasonCode = "each_child_dependency"
	// ErrorReasonCodeSubFuncLinkArgResourceNotFound is provided when the reason
	// for a blueprint spec load error is due to a resource not being found
	// in an argument to the "link" substitution function.
	ErrorReasonCodeSubFuncLinkArgResourceNotFound errors.ErrorReasonCode = "sub_func_link_arg_resource_not_found"
)
View Source
const (
	// TransformCelerity2025_08_01 is the transform to be used for
	// Celerity resources that provide an abstraction over a more complex
	// combination of underlying resources.
	TransformCelerity2025_08_01 = "celerity-2025-08-01"
)
View Source
const (
	// Version2025_05_12 is the version of the blueprint specification
	// that is the sole version of the spec supported by the initial
	// version of the blueprint framework.
	Version2025_05_12 = "2025-05-12"
)

Variables

View Source
var (
	// CoreTransforms is the list of transforms that are considered to be core
	// to Celerity, these will be transforms maintained by the Celerity team
	// or by trusted maintainers.
	CoreTransforms = []string{
		TransformCelerity2025_08_01,
	}
)
View Source
var (
	// ExportCanReference is a list of objects that can be referenced
	// by an export.
	// In the current version of the specification, resources, data sources,
	// variables, values and child blueprints can be referenced by an export.
	ExportCanReference = []Referenceable{
		ReferenceableResource,
		ReferenceableDataSource,
		ReferenceableVariable,
		ReferenceableValue,
		ReferenceableChild,
	}
)
View Source
var (
	// SupportedVersions is the list of versions of the blueprint
	// specification that are supported by this version of the blueprint
	// framework.
	SupportedVersions = []string{
		Version2025_05_12,
	}
)

Functions

func CreateDependencyRefTag

func CreateDependencyRefTag(usedIn string) string

CreateDependencyRefTag creates a reference chain node tag for a dependency reference defined in a blueprint resource with the "dependsOn" property.

func CreateLinkTag

func CreateLinkTag(linkDependencyOf string) string

CreateLinkTag creates a reference chain node tag for a dependency resource that is linked to or from another resource. This should contain the name of the resource that depends on the resource being tagged.

func CreateSubRefPropTag

func CreateSubRefPropTag(usedIn string, usedInPropPath string) string

CreateSubRefPropTag creates a reference chain node tag for a substitution reference including the property path within the resource that holds the reference.

func CreateSubRefTag

func CreateSubRefTag(usedIn string) string

CreateSubRefTag creates a reference chain node tag for a substitution reference.

func ErrMultipleValidationErrors

func ErrMultipleValidationErrors(errs []error) error

errMultipleValidationErrors is used to wrap multiple errors that occurred during validation. The idea is to collect and surface as many validation errors to the user as possible to provide them the full picture of issues in the blueprint instead of just the first error.

func ErrReferenceCycles

func ErrReferenceCycles(rootRefChains []*refgraph.ReferenceChainNode) error

ErrReferenceCycles is used to wrap errors that occurred during reference cycle validation. This error is used to collect and surface reference cycle errors for pure substitution reference cycles and link <-> substitution reference cycles.

func ExtractDiagnosticsAndErrors

func ExtractDiagnosticsAndErrors(
	diagnostics []*core.Diagnostic,
	errorReasonCode bperrors.ErrorReasonCode,
) ([]*core.Diagnostic, error)

ExtractDiagnosticsAndErrors extracts diagnostics and errors from the provided diagnostics slice. It returns a slice of diagnostics that are not errors, and a wrapper error for multiple validation errors assigned the given reason code if any are found.

func PreValidateResourceSpec

func PreValidateResourceSpec(
	ctx context.Context,
	resourceName string,
	resourceSchema *schema.Resource,
	resourceMap *schema.ResourceMap,
) error

PreValidateResourceSpec pre-validates the resource specification against the blueprint specification. This primarily searches for invalid usage of substitutions in mapping keys. The main resource validation that invokes a user-provided resource implementation comes after this.

func ValidateBlueprint

func ValidateBlueprint(ctx context.Context, blueprint *schema.Blueprint) ([]*bpcore.Diagnostic, error)

ValidateBlueprint ensures that the required top-level properties of a blueprint are populated. (When they are populated the schema takes care of the structure)

func ValidateCoreVariable

func ValidateCoreVariable(
	ctx context.Context,
	varName string,
	varSchema *schema.Variable,
	varMap *schema.VariableMap,
	params bpcore.BlueprintParams,
	validateRuntimeParams bool,
) ([]*bpcore.Diagnostic, error)

ValidateCoreVariable deals with validating a blueprint variable against the supported core scalar variable types in the blueprint specification.

func ValidateCustomVariable

func ValidateCustomVariable(
	ctx context.Context,
	varName string,
	varSchema *schema.Variable,
	varMap *schema.VariableMap,
	params bpcore.BlueprintParams,
	customVariableType provider.CustomVariableType,
	validateRuntimeParams bool,
) ([]*bpcore.Diagnostic, error)

ValidateCustomVariable validates a custom variable in a blueprint. This validation spans all the fields of a variable in the parsed schema as well as the runtime variable value provided by the user.

func ValidateDataSource

func ValidateDataSource(
	ctx context.Context,
	name string,
	dataSource *schema.DataSource,
	dataSourceMap *schema.DataSourceMap,
	bpSchema *schema.Blueprint,
	params bpcore.BlueprintParams,
	funcRegistry provider.FunctionRegistry,
	refChainCollector refgraph.RefChainCollector,
	resourceRegistry resourcehelpers.Registry,
	dataSourceRegistry provider.DataSourceRegistry,
	logger bpcore.Logger,
) ([]*bpcore.Diagnostic, error)

ValidateDataSource ensures that a given data source matches the specification.

func ValidateDataSourceName

func ValidateDataSourceName(mappingName string, dataSourceMap *schema.DataSourceMap) error

ValidateDataSourceName checks the validity of a data source name, primarily making sure that it does not contain any substitutions as per the spec.

func ValidateExport

func ValidateExport(
	ctx context.Context,
	exportName string,
	exportSchema *schema.Export,
	exportMap *schema.ExportMap,
	bpSchema *schema.Blueprint,
	params bpcore.BlueprintParams,
	funcRegistry provider.FunctionRegistry,
	refChainCollector refgraph.RefChainCollector,
	resourceRegistry resourcehelpers.Registry,
	dataSourceRegistry provider.DataSourceRegistry,
) ([]*bpcore.Diagnostic, error)

ValidateExport validates an export in a blueprint. This ensures that the export type is valid and that the referenced field is in the valid format. This does not validate that the field of the export can not be resolved, as this export validation should be carried out before staging changes or deploying a blueprint.

func ValidateInclude

func ValidateInclude(
	ctx context.Context,
	includeName string,
	includeSchema *schema.Include,
	includeMap *schema.IncludeMap,
	bpSchema *schema.Blueprint,
	params core.BlueprintParams,
	funcRegistry provider.FunctionRegistry,
	refChainCollector refgraph.RefChainCollector,
	resourceRegistry resourcehelpers.Registry,
	dataSourceRegistry provider.DataSourceRegistry,
) ([]*core.Diagnostic, error)

ValidateInclude deals with early stage validation of a child blueprint include. This validation is primarily responsible for ensuring the path of an include is not empty and that any substitutions used are valid. As we don't have enough extra information at the early stage at which this should run, it does not include validation of the path format or variables. Variable validation requires information about the variables that are available in the child blueprint, which is not available at this stage.

func ValidateIncludeName

func ValidateIncludeName(mappingName string, includeMap *schema.IncludeMap) error

ValidateIncludeName checks the validity of a include name, primarily making sure that it does not contain any substitutions as per the spec.

func ValidateLinkAnnotations

func ValidateLinkAnnotations(
	ctx context.Context,
	linkChains []*links.ChainLinkNode,
	params core.BlueprintParams,
) ([]*core.Diagnostic, error)

ValidateLinkAnnotations checks the validity of link annotations for one or more link chains represented as a graph-like data structure where resources are nodes and links are edges.

Each annotation is checked against the link annotation definitions for the provider plugin link implementation that connects two resources. This is intended to be used at the end of the validation process once a graph of resources and links has been built after all other elements in a blueprint have been validated. This must only be called after the provided link chains have been checked for cycles.

This validation supports dynamic annotation keys that can contain a single "<resourceName>" placeholder string. The value that "<resourceName>" represents must be the name of a resource that is linked to the resource type where the annotation is defined. Only a single "<resourceName>" placeholder is allowed for a dynamic annotation key. Dynamic keys are used to target specific resources when there are multiple resources of the same type linked to the resource where the annotation is defined. Default values are ignored for link annotation field definitions that have dynamic field names, the default value should be defined in an equivalent annotation that is not targeted at a specific resource name (e.g. "aws.lambda.dynamodb.accessType").

When an annotation definition with a dynamic name is required, it means that at least one annotation value that matches the pattern must be present.

Unknown annotation keys are ignored, allowing them to be used for other purposes.

This returns an error for any unexpected errors and will return a list of diagnostics for any validation errors and warnings.

func ValidateMappingNode

func ValidateMappingNode(
	ctx context.Context,
	usedIn string,

	attributePath string,
	usedInResourceDerivedFromTemplate bool,
	mappingNode *bpcore.MappingNode,
	bpSchema *schema.Blueprint,
	params bpcore.BlueprintParams,
	funcRegistry provider.FunctionRegistry,
	refChainCollector refgraph.RefChainCollector,
	resourceRegistry resourcehelpers.Registry,
	dataSourceRegistry provider.DataSourceRegistry,
) ([]*bpcore.Diagnostic, error)

ValidateMappingNode ensures that all the substitutions used in a mapping node are valid. This is to be used in free form mapping nodes such as `metadata.custom` in data sources and resources.

func ValidateReference

func ValidateReference(
	reference string,
	context string,
	hasAccessTo []Referenceable,
	location *source.Meta,
) error

ValidateReference validates a reference in a blueprint, a reference can be to a variable, resource, child blueprint or data source. This validation does not validate that the reference can be resolved, as this validation will normally be carried out at an early stage before information is available about what resources, variables, data sources or child blueprints are available.

func ValidateResource

func ValidateResource(
	ctx context.Context,
	name string,
	resource *schema.Resource,
	resourceMap *schema.ResourceMap,
	bpSchema *schema.Blueprint,
	params bpcore.BlueprintParams,
	funcRegistry provider.FunctionRegistry,
	refChainCollector refgraph.RefChainCollector,
	resourceRegistry resourcehelpers.Registry,
	resourceDerivedFromTemplate bool,
	logger bpcore.Logger,
	dataSourceRegistry provider.DataSourceRegistry,
) ([]*bpcore.Diagnostic, error)

ValidateResource ensures that a given resource is valid as per the blueprint specification and the resource type specification definition exposed by the resource type provider.

func ValidateResourceEachDependencies

func ValidateResourceEachDependencies(
	blueprint *schema.Blueprint,
	refChainCollector refgraph.RefChainCollector,
) error

ValidateResourceEachDependencies validates the dependencies of the `each` property of a resource. This should be called after all validation of a blueprint has been carried out and the full set of references have been collected.

func ValidateResourceName

func ValidateResourceName(mappingName string, resourceMap *schema.ResourceMap) error

ValidateResourceName checks the validity of a resource name, primarily making sure that it does not contain any substitutions as per the spec.

func ValidateResourceSpec

func ValidateResourceSpec(
	ctx context.Context,
	name string,
	resourceType string,
	resourceDerivedFromTemplate bool,
	resource *schema.Resource,
	resourceLocation *source.Meta,
	bpSchema *schema.Blueprint,
	params core.BlueprintParams,
	funcRegistry provider.FunctionRegistry,
	refChainCollector refgraph.RefChainCollector,
	resourceRegistry resourcehelpers.Registry,
	dataSourceRegistry provider.DataSourceRegistry,
) ([]*core.Diagnostic, error)

ValidateResourceSpec validates the `spec` field of a resource. In a blueprint, this is a free form object that can hold complex structures that define a resource's configuration. Each resource has its own schema that is defined by the provider, this function validates against that schema and runs custom validation defined by the provider. This will only traverse up to `MappingNodeMaxTraverseDepth` levels deep, if the depth is exceeded, validation will not be performed on further elements.

func ValidateSubstitution

func ValidateSubstitution(
	ctx context.Context,
	sub *substitutions.Substitution,
	nextLocation *source.Meta,
	bpSchema *schema.Blueprint,
	usedInResourceDerivedFromTemplate bool,
	usedIn string,

	usedInPropertyPath string,
	params bpcore.BlueprintParams,
	funcRegistry provider.FunctionRegistry,
	refChainCollector refgraph.RefChainCollector,
	resourceRegistry resourcehelpers.Registry,
	dataSourceRegistry provider.DataSourceRegistry,
) (string, []*bpcore.Diagnostic, error)

ValidateSubstitution validates a substitution usage in a blueprint.

usedIn is the path to the element in the blueprint where the substitution is used. This should be in the format of "{elementType}.{elementName}" For example, "values.myValue" or "resources.myResource"

funcRegistry provides a registry of functions that can be used in the substitution. resourceRegistry provides a registry of resource types that are used to check accessed attributes against the resource spec.

This returns a string containing the type of the resolved value for the substitution where it can be determined, an empty string otherwise. The caller is responsible for ensuring that the resolved value type is compatible with the context where the substitution is used. It also returns a list of diagnostics that were generated during the validation process and an error if the validation process failed.

func ValidateTransforms

func ValidateTransforms(
	ctx context.Context,
	blueprint *schema.Blueprint,
	specWillBeTransformed bool,
) ([]*bpcore.Diagnostic, error)

ValidateTransforms checks for non-standard transforms and reports warnings when the spec is not going to be transformed (e.g. dry run validation).

func ValidateValue

func ValidateValue(
	ctx context.Context,
	valName string,
	valSchema *schema.Value,
	bpSchema *schema.Blueprint,
	params bpcore.BlueprintParams,
	funcRegistry provider.FunctionRegistry,
	refChainCollector refgraph.RefChainCollector,
	resourceRegistry resourcehelpers.Registry,
	dataSourceRegistry provider.DataSourceRegistry,
) ([]*bpcore.Diagnostic, error)

ValidateValue deals with validating a blueprint value against the supported value types in the blueprint specification.

func ValidateValueName

func ValidateValueName(mappingName string, valMap *schema.ValueMap) error

ValidateValueName checks the validity of a value name, primarily making sure that it does not contain any substitutions as per the spec.

func ValidateVariableName

func ValidateVariableName(mappingName string, varMap *schema.VariableMap) error

ValidateVariableName checks the validity of a variable name, primarily making sure that it does not contain any substitutions as per the spec.

Types

type Referenceable

type Referenceable string

Referencable is a type that can be referenced in a blueprint.

const (
	// ReferenceableResource signifies that a resource
	// can be referenced for a given context in a blueprint.
	ReferenceableResource Referenceable = "resource"
	// ReferenceableVariable signifies that a variable
	// can be referenced for a given context in a blueprint.
	ReferenceableVariable Referenceable = "variable"
	// ReferenceableValue signifies that a value
	// can be referenced for a given context in a blueprint.
	ReferenceableValue Referenceable = "value"
	// ReferenceableDataSource signifies that a data source
	// can be referenced for a given context in a blueprint.
	ReferenceableDataSource Referenceable = "datasource"
	// ReferenceableChild signifies that a child blueprint
	// can be referenced for a given context in a blueprint.
	ReferenceableChild Referenceable = "child"
)

Jump to

Keyboard shortcuts

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